├── .gitignore ├── .gitmodules ├── .travis.yml ├── Kconfig ├── LICENSE ├── README.md ├── assets └── image │ ├── build.gif │ └── use_template.png ├── components ├── drivers │ ├── CMakeLists.txt │ ├── Kconfig │ ├── audio │ │ ├── Kconfig │ │ ├── es8374 │ │ │ ├── include │ │ │ │ ├── es8374.h │ │ │ │ └── music_play.h │ │ │ └── src │ │ │ │ ├── es8374.c │ │ │ │ ├── maix_i2s.c │ │ │ │ └── music_play.c │ │ ├── include │ │ │ └── audio.h │ │ ├── pt8211 │ │ │ ├── include │ │ │ │ ├── audio_mic.h │ │ │ │ └── audio_speaker.h │ │ │ └── src │ │ │ │ ├── audio_mic.c │ │ │ │ └── audio_speaker.c │ │ └── src │ │ │ └── audio.c │ ├── camera │ │ ├── Kconfig │ │ ├── include │ │ │ └── camera.h │ │ ├── ov2640 │ │ │ ├── include │ │ │ │ └── ov2640.h │ │ │ └── src │ │ │ │ └── ov2640.c │ │ └── src │ │ │ └── camera.c │ ├── lcd │ │ ├── Kconfig │ │ ├── include │ │ │ └── lcd.h │ │ ├── lcd_sipeed │ │ │ ├── include │ │ │ │ └── lcd_sipeed.h │ │ │ └── src │ │ │ │ └── lcd_sipeed.c │ │ ├── lcd_st7789 │ │ │ ├── include │ │ │ │ ├── lcd_st7789.h │ │ │ │ └── nt35310.h │ │ │ └── src │ │ │ │ ├── lcd_st7789.c │ │ │ │ └── nt35310.c │ │ └── src │ │ │ └── lcd.c │ ├── mem_macro │ │ └── mem_macro.h │ ├── rtc │ │ ├── Kconfig │ │ ├── bm8563 │ │ │ ├── include │ │ │ │ └── bm8563.h │ │ │ └── src │ │ │ │ └── bm8563.c │ │ ├── gm1302 │ │ │ ├── include │ │ │ │ └── gm1302.h │ │ │ └── src │ │ │ │ └── gm1302.c │ │ ├── include │ │ │ └── sipeed_rtc.h │ │ └── src │ │ │ └── sipeed_rtc.c │ └── sd_card │ │ ├── Kconfig │ │ ├── include │ │ └── sd_card.h │ │ └── src │ │ └── sd_card.c ├── kendryte_sdk │ ├── CMakeLists.txt │ └── Kconfig ├── third_party │ ├── CMakeLists.txt │ ├── Kconfig │ └── oofatfs │ │ ├── include │ │ ├── diskio.h │ │ ├── ff.h │ │ └── ffconf.h │ │ ├── option │ │ ├── ccsbcs.c │ │ └── unicode.c0 │ │ └── src │ │ ├── diskio.c │ │ └── ff.c └── utils │ ├── CMakeLists.txt │ ├── Kconfig │ ├── base64 │ ├── include │ │ └── base64.h │ └── src │ │ └── base64.c │ ├── cJSON │ ├── include │ │ ├── cJSON.h │ │ └── cJSON_Utils.h │ └── src │ │ ├── cJSON.c │ │ └── cJSON_Utils.c │ ├── image_op │ ├── include │ │ ├── ascii_font.h │ │ └── image_op.h │ ├── src │ │ ├── ascii_font.c │ │ └── image_op.c │ └── zhCN_FONT │ │ ├── GB2312 │ │ ├── GB2312.txt │ │ ├── GB2312_16_32.kfpkg │ │ ├── GB2312_16x16.FON │ │ ├── GB2312_32x32.FON │ │ └── gen_gb2312.c │ │ └── GBK │ │ ├── GBK12.FON │ │ ├── GBK16.FON │ │ ├── GBK24.FON │ │ ├── GBK32.FON │ │ └── UNIGBK.BIN │ ├── jpeg_decode │ ├── include │ │ ├── picojpeg.h │ │ └── picojpeg_util.h │ └── src │ │ ├── picojpeg.c │ │ └── picojpeg_util.c │ ├── jpeg_encode │ ├── include │ │ └── jpeg_encode.h │ └── src │ │ └── jpeg_encode.c │ ├── list │ ├── .gitignore │ ├── .travis.yml │ ├── History.md │ ├── Makefile │ ├── Readme.md │ ├── benchmark.c │ ├── package.json │ ├── src │ │ ├── list.c │ │ ├── list.h │ │ ├── list_iterator.c │ │ ├── list_mem.c │ │ └── list_node.c │ └── test.c │ ├── qrcode │ ├── Kconfig │ ├── include │ │ └── maix_qrcode.h │ ├── quirc │ │ ├── include │ │ │ └── quirc.h │ │ └── src │ │ │ └── quirc.c │ ├── src │ │ └── maix_qrcode.c │ └── zbar │ │ └── src │ │ ├── bch15_5.c │ │ ├── bch15_5.h │ │ ├── binarize.c │ │ ├── binarize.h │ │ ├── config.h │ │ ├── debug.h │ │ ├── decoder.c │ │ ├── decoder.h │ │ ├── error.c │ │ ├── error.h │ │ ├── image.c │ │ ├── image.h │ │ ├── img_scanner.c │ │ ├── img_scanner.h │ │ ├── isaac.c │ │ ├── isaac.h │ │ ├── qr_finder.c │ │ ├── qr_finder.h │ │ ├── qrcode.h │ │ ├── qrdec.c │ │ ├── qrdec.h │ │ ├── qrdectxt.c │ │ ├── refcnt.c │ │ ├── refcnt.h │ │ ├── rs.c │ │ ├── rs.h │ │ ├── scanner.c │ │ ├── symbol.c │ │ ├── symbol.h │ │ ├── util.c │ │ ├── util.h │ │ ├── zbar.c │ │ └── zbar.h │ └── yuv_tab │ ├── include │ └── yuv_tab.h │ └── src │ └── yuv_tab.c ├── projects ├── MF1 │ ├── .gitignore │ ├── CMakeLists.txt │ ├── compile │ │ ├── compile_flags.cmake │ │ ├── gen_binary.cmake │ │ ├── kendryte.ld │ │ └── priority.conf │ ├── config │ │ ├── client1_default.mk │ │ ├── config_defaults.mk.0 │ │ ├── config_defaults.mk.1 │ │ ├── config_defaults.mk.2 │ │ └── config_defaults.mk.3 │ ├── config_defaults.mk │ ├── main │ │ ├── CMakeLists.txt │ │ ├── Kconfig │ │ ├── blur_detect │ │ │ ├── blur_detect.c │ │ │ ├── blur_detect.h │ │ │ ├── layer.c │ │ │ └── layer.h │ │ ├── face_lib │ │ │ ├── face_cb.c │ │ │ ├── face_cb.h │ │ │ ├── face_lib.h │ │ │ ├── lcd_dis.c │ │ │ ├── lcd_dis.h │ │ │ └── lib │ │ │ │ ├── lib_face_dual_hor.a │ │ │ │ ├── lib_face_dual_ver.a │ │ │ │ ├── lib_face_single_hor.a │ │ │ │ └── lib_face_single_ver.a │ │ ├── include │ │ │ ├── board.h │ │ │ ├── core1.h │ │ │ ├── flash.h │ │ │ ├── system_config.h │ │ │ └── user_cmd.h │ │ ├── network │ │ │ ├── esp8285 │ │ │ │ ├── demo_esp8285.c │ │ │ │ ├── demo_esp8285.h │ │ │ │ ├── http │ │ │ │ │ ├── http_file.c │ │ │ │ │ ├── http_file.h │ │ │ │ │ ├── http_save_file.c │ │ │ │ │ ├── http_save_file.h │ │ │ │ │ ├── http_simple.c │ │ │ │ │ ├── http_simple.h │ │ │ │ │ ├── mt_str.c │ │ │ │ │ ├── my_str.h │ │ │ │ │ ├── parsed_url.c │ │ │ │ │ └── parsed_url.h │ │ │ │ ├── mqtt │ │ │ │ │ ├── PubSubClient.c │ │ │ │ │ └── PubSubClient.h │ │ │ │ ├── net_8285.c │ │ │ │ ├── net_8285.h │ │ │ │ └── wifi │ │ │ │ │ ├── WiFiSpi.c │ │ │ │ │ ├── WiFiSpi.h │ │ │ │ │ ├── WiFiSpiClient.c │ │ │ │ │ ├── WiFiSpiClient.h │ │ │ │ │ ├── WiFiSpiServer.c │ │ │ │ │ ├── WiFiSpiServer.h │ │ │ │ │ ├── WiFiSpiUdp.c │ │ │ │ │ ├── WiFiSpiUdp.h │ │ │ │ │ ├── spi │ │ │ │ │ ├── myspi.c │ │ │ │ │ └── myspi.h │ │ │ │ │ └── utility │ │ │ │ │ ├── config.h │ │ │ │ │ ├── espspi_drv.c │ │ │ │ │ ├── espspi_drv.h │ │ │ │ │ ├── espspi_proxy.c │ │ │ │ │ ├── espspi_proxy.h │ │ │ │ │ ├── srvspi_drv.c │ │ │ │ │ ├── srvspi_drv.h │ │ │ │ │ ├── wifi_spi.h │ │ │ │ │ ├── wifispi_drv.c │ │ │ │ │ ├── wifispi_drv.h │ │ │ │ │ ├── wl_definitions.h │ │ │ │ │ └── wl_types.h │ │ │ └── w5500 │ │ │ │ ├── arduino_lib.txt │ │ │ │ ├── demo_w5500.c │ │ │ │ ├── demo_w5500.h │ │ │ │ ├── httpc │ │ │ │ ├── http_file.c │ │ │ │ ├── http_file.h │ │ │ │ ├── http_save_file.c │ │ │ │ ├── http_save_file.h │ │ │ │ ├── http_simple.c │ │ │ │ ├── http_simple.h │ │ │ │ ├── my_str.c │ │ │ │ ├── my_str.h │ │ │ │ ├── parsed_url.c │ │ │ │ └── parsed_url.h │ │ │ │ ├── httpd │ │ │ │ ├── src │ │ │ │ │ ├── httpd.c │ │ │ │ │ ├── httpd.h │ │ │ │ │ ├── httpd_mime.h │ │ │ │ │ ├── httpd_util.c │ │ │ │ │ ├── match.c │ │ │ │ │ ├── match.h │ │ │ │ │ ├── mini_httpd-1.30.tar.gz │ │ │ │ │ ├── tdate_parse.c │ │ │ │ │ └── tdate_parse.h │ │ │ │ └── web_pages │ │ │ │ │ ├── html │ │ │ │ │ └── index.html │ │ │ │ │ ├── incbin.h │ │ │ │ │ ├── web_config.h │ │ │ │ │ ├── webpage.c │ │ │ │ │ └── webpage.h │ │ │ │ ├── mqtt │ │ │ │ ├── mqtt.c │ │ │ │ └── mqtt.h │ │ │ │ ├── spi │ │ │ │ ├── myspi.c │ │ │ │ └── myspi.h │ │ │ │ └── src │ │ │ │ ├── Dhcp.c │ │ │ │ ├── Dhcp.h │ │ │ │ ├── Dns.c │ │ │ │ ├── Dns.h │ │ │ │ ├── Ethernet.c │ │ │ │ ├── Ethernet.h │ │ │ │ ├── EthernetClient.c │ │ │ │ ├── EthernetClient.h │ │ │ │ ├── EthernetServer.c │ │ │ │ ├── EthernetServer.h │ │ │ │ ├── EthernetUdp.c │ │ │ │ ├── EthernetUdp.h │ │ │ │ └── utility │ │ │ │ ├── socket.c │ │ │ │ ├── socket.h │ │ │ │ ├── util.h │ │ │ │ ├── w5100.c │ │ │ │ └── w5100.h │ │ ├── sd_op │ │ │ ├── include │ │ │ │ └── sd_op.h │ │ │ └── src │ │ │ │ └── sd_op.c │ │ ├── src │ │ │ ├── board.c │ │ │ ├── core1.c │ │ │ ├── flash.c │ │ │ ├── main.c │ │ │ └── user_cmd.c │ │ ├── uart_recv │ │ │ ├── uart_recv.c │ │ │ └── uart_recv.h │ │ └── ui │ │ │ └── pic │ │ │ ├── 0.bmp │ │ │ ├── 1.bmp │ │ │ ├── 2.bmp │ │ │ ├── 3.bmp │ │ │ ├── 4.bmp │ │ │ ├── 5.bmp │ │ │ ├── 6.bmp │ │ │ ├── bmp2hex.py │ │ │ ├── flash-list.json │ │ │ ├── gen_imgbin.sh │ │ │ ├── merge_kfpkg.py │ │ │ ├── pack_kfpkg.py │ │ │ └── pic_merge_quad.kfpkg │ └── project.py └── hello_world │ ├── .gitignore │ ├── CMakeLists.txt │ ├── compile │ ├── compile_flags.cmake │ ├── gen_binary.cmake │ ├── kendryte.ld │ └── priority.conf │ ├── config_defaults.mk │ ├── main │ ├── CMakeLists.txt │ └── src │ │ └── main.c │ └── project.py ├── requirements.txt └── tools ├── cmake ├── compile.cmake ├── compile_flags.cmake ├── gen_binary.cmake ├── project.py ├── sort_components.py └── tools.cmake ├── docker ├── Dockerfile └── README.md ├── flash ├── flash.py └── kfpkg.py ├── kconfig ├── genconfig.py └── update_build_info.py └── release ├── .gitignore └── release.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | build 55 | .vscode 56 | .config 57 | .config.old 58 | 59 | 60 | # python 61 | *.pyc 62 | __pycache__ 63 | 64 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tools/kconfig/Kconfiglib"] 2 | path = tools/kconfig/Kconfiglib 3 | url = https://github.com/ulfalizer/Kconfiglib.git 4 | [submodule "tools/flash/kflash_py"] 5 | path = tools/flash/kflash_py 6 | url = https://github.com/sipeed/kflash.py.git 7 | [submodule "components/kendryte_sdk/kendryte-standalone-sdk"] 8 | path = components/kendryte_sdk/kendryte-standalone-sdk 9 | url = https://github.com/sipeed/kendryte-standalone-sdk.git 10 | [submodule "components/utils/cQueue"] 11 | path = components/utils/cQueue 12 | url = https://github.com/SMFSW/cQueue.git 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: 2 | - c 3 | compiler: 4 | - gcc 5 | cache: 6 | directories: 7 | - "${HOME}/.build_cache" 8 | env: 9 | global: 10 | - rev=$(git rev-parse --short HEAD) 11 | - BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi) 12 | - curr_branch=$TRAVIS_BRANCH 13 | branches: 14 | only: 15 | - dev 16 | 17 | stages: 18 | - name: mf1_build 19 | 20 | jobs: 21 | include: 22 | - stage: mf1_build 23 | env: NAME="mf1 build" 24 | install: 25 | - sudo apt-get update 26 | - sudo apt-get install -y sshpass p7zip-full 27 | - wget https://github.com/kendryte/kendryte-gnu-toolchain/releases/download/v8.2.0-20190409/kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz 28 | - sudo tar -Jxf kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz -C /opt 29 | - rm -f kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz 30 | script: 31 | - echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, BRANCH=$BRANCH" 32 | - cd tools/release 33 | - chmod +x release.sh && ./release.sh || travis_terminate 1; 34 | - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then exit 0; fi 35 | - time_now=$(date "+%Y_%m_%d_%H_%M_%S") 36 | - cd bin 37 | - firmware_dir=`ls` 38 | - sudo sh -c "echo StrictHostKeyChecking no >>/etc/ssh/ssh_config" 39 | - sshpass -p ${USER_PASSWD} scp -r $firmware_dir ${SERVER_USER}@${SERVER_ADDR}:${SERVER_FOLDER_PATH}/${curr_branch}/ 40 | -------------------------------------------------------------------------------- /Kconfig: -------------------------------------------------------------------------------- 1 | 2 | mainmenu "C/CPP CMake project framework Kconfig configuration" 3 | 4 | menu "Toolchain configuration" 5 | config TOOLCHAIN_PATH 6 | string "toolchain path" 7 | default "/opt/kendryte-toolchain/bin" 8 | 9 | config TOOLCHAIN_PREFIX 10 | string "toolchain prefix" 11 | default "riscv64-unknown-elf-" 12 | endmenu 13 | 14 | menu "Components configuration" 15 | osource "${SDK_PATH}/components/*/Kconfig" 16 | endmenu 17 | 18 | osource "${PROJECT_PATH}/*/Kconfig" -------------------------------------------------------------------------------- /assets/image/build.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/assets/image/build.gif -------------------------------------------------------------------------------- /assets/image/use_template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/assets/image/use_template.png -------------------------------------------------------------------------------- /components/drivers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | list(APPEND ADD_INCLUDE "mem_macro" 2 | #audio 3 | "audio/include" 4 | "audio/es8374/include" 5 | "audio/pt8211/include" 6 | #camera 7 | "camera/include" 8 | "camera/ov2640/include" 9 | #lcd 10 | "lcd/include" 11 | "lcd/lcd_st7789/include" 12 | "lcd/lcd_sipeed/include" 13 | #rtc 14 | "rtc/include" 15 | "rtc/gm1302/include" 16 | "rtc/bm8563/include" 17 | #sd card 18 | "sd_card/include" 19 | ) 20 | 21 | if(CONFIG_ENABLE_SPK) 22 | append_srcs_dir(ADD_SRCS "audio/src") 23 | 24 | if(CONFIG_SPK_TYPE_ES8374) 25 | append_srcs_dir(ADD_SRCS "audio/es8374/src") 26 | elseif(CONFIG_SPK_TYPE_PT8211) 27 | append_srcs_dir(ADD_SRCS "audio/pt8211/src") 28 | endif() 29 | endif() 30 | 31 | if(CONFIG_ENABLE_CAMERA) 32 | append_srcs_dir(ADD_SRCS "camera/src") 33 | 34 | if(CONFIG_CAMERA_OV2640) 35 | append_srcs_dir(ADD_SRCS "camera/ov2640/src") 36 | endif() 37 | endif() 38 | 39 | if(CONFIG_ENABLE_LCD) 40 | append_srcs_dir(ADD_SRCS "lcd/src") 41 | 42 | if(CONFIG_LCD_TYPE_ST7789) 43 | append_srcs_dir(ADD_SRCS "lcd/lcd_st7789/src") 44 | elseif(CONFIG_LCD_TYPE_SIPEED) 45 | # append_srcs_dir(ADD_SRCS "lcd/lcd_sipeed/src") 46 | message(FATAL_ERROR "not support this LCD Driver") 47 | endif() 48 | endif() 49 | 50 | if(CONFIG_ENABLE_RTC) 51 | append_srcs_dir(ADD_SRCS "rtc/src") 52 | 53 | if(CONFIG_RTC_TYPE_GM1302) 54 | append_srcs_dir(ADD_SRCS "rtc/gm1302/src") 55 | elseif(CONFIG_RTC_TYPE_BM8563) 56 | append_srcs_dir(ADD_SRCS "rtc/bm8563/src") 57 | endif() 58 | endif() 59 | 60 | if(CONFIG_ENABLE_SD_CARD) 61 | append_srcs_dir(ADD_SRCS "sd_card/src") 62 | endif() 63 | 64 | list(APPEND ADD_REQUIREMENTS kendryte_sdk) 65 | 66 | register_component() 67 | -------------------------------------------------------------------------------- /components/drivers/Kconfig: -------------------------------------------------------------------------------- 1 | 2 | menu "Drivers configuration" 3 | 4 | #audio 5 | osource "${SDK_PATH}/components/drivers/audio/Kconfig" 6 | 7 | # camera 8 | osource "${SDK_PATH}/components/drivers/camera/Kconfig" 9 | 10 | # lcd 11 | osource "${SDK_PATH}/components/drivers/lcd/Kconfig" 12 | 13 | #rtc 14 | osource "${SDK_PATH}/components/drivers/rtc/Kconfig" 15 | 16 | # sd_card 17 | osource "${SDK_PATH}/components/drivers/sd_card/Kconfig" 18 | 19 | endmenu 20 | -------------------------------------------------------------------------------- /components/drivers/audio/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Audio Speaker" 2 | config ENABLE_SPK 3 | bool "enable speaker" 4 | default n 5 | 6 | choice SPK_TYPE 7 | depends on ENABLE_SPK 8 | bool "speaker type" 9 | default SPK_TYPE_PT8211 10 | 11 | config SPK_TYPE_ES8374 12 | bool "speaker use es8374" 13 | 14 | config SPK_TYPE_PT8211 15 | bool "speaker use pt8211" 16 | endchoice 17 | 18 | menu "ES8374 Pin configuration" 19 | depends on SPK_TYPE_ES8374 20 | 21 | config PIN_NUM_ES8374_MCLK 22 | int "es8374 pin mclk" 23 | default 19 24 | config PIN_NUM_ES8374_DIN 25 | int "es8374 pin din" 26 | default 18 27 | config PIN_NUM_ES8374_DOUT 28 | int "es8374 pin dout" 29 | default 34 30 | config PIN_NUM_ES8374_SCLK 31 | int "es8374 pin sclk" 32 | default 35 33 | config PIN_NUM_ES8374_WS 34 | int "es8374 pin ws" 35 | default 33 36 | 37 | config PIN_NUM_ES8374_I2C_SDA 38 | int "es8374 pin i2c sda" 39 | default 31 40 | 41 | config PIN_NUM_ES8374_I2C_SCL 42 | int "es8374 pin i2c scl" 43 | default 30 44 | endmenu 45 | 46 | menu "PT8211 configuration" 47 | depends on SPK_TYPE_PT8211 48 | 49 | config PIN_NUM_PT8211_DAT 50 | int "pt8211 dat pin num" 51 | default 18 52 | config PIN_NUM_PT8211_CLK 53 | int "pt8211 clk pin num" 54 | default 35 55 | config PIN_NUM_PT8211_WS 56 | int "pt8211 ws pin num" 57 | default 33 58 | config PIN_NUM_PT8211_PA_EN 59 | int "pt8211 pa_en pin num" 60 | default 11 61 | 62 | comment "------------------------------------------" 63 | 64 | config GPIO_NUM_PT8211_PA_EN 65 | int "gpio num of pt8211 pa en" 66 | default 2 67 | endmenu 68 | endmenu 69 | -------------------------------------------------------------------------------- /components/drivers/audio/es8374/include/music_play.h: -------------------------------------------------------------------------------- 1 | #ifndef __MUSIC_PLAY_H 2 | #define __MUSIC_PLAY_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "i2s.h" 9 | 10 | #include "audio.h" 11 | 12 | /* clang-format off */ 13 | // #define ES8374_I2C_SDA (31) 14 | // #define ES8374_I2C_SCL (30) 15 | 16 | // #define ES8374_I2S_DIN (18) 17 | // #define ES8374_I2S_MCLK (19) 18 | 19 | // #define ES8374_I2S_WS (33) 20 | // #define ES8374_I2S_DOUT (34) 21 | // #define ES8374_I2S_SCLK (35) 22 | /* clang-format on */ 23 | 24 | void maix_i2s_init(i2s_device_number_t device_num, uint32_t rx_channel_mask, uint32_t tx_channel_mask); 25 | 26 | void maix_i2s_play(i2s_device_number_t device_num, dmac_channel_number_t channel_num, 27 | const uint8_t *buf, size_t buf_len, size_t frame, size_t bits_per_sample, uint8_t track_num); 28 | 29 | uint8_t music_play_init(void); 30 | 31 | uint8_t audio_es8374_init(audio_t *audio); 32 | 33 | #endif /* __MUSIC_PLAY_H */ 34 | -------------------------------------------------------------------------------- /components/drivers/audio/include/audio.h: -------------------------------------------------------------------------------- 1 | #ifndef __AUDIO_H 2 | #define __AUDIO_H 3 | 4 | #include 5 | 6 | typedef enum 7 | { 8 | AUDIO_TYPE_ES8374 = 0, 9 | AUDIO_TYPE_PT8211, 10 | AUDIO_TYPE_MAX, 11 | } audio_type; 12 | 13 | typedef struct _autio audio_t; 14 | 15 | typedef struct _autio 16 | { 17 | uint8_t (*config)(void); 18 | 19 | /* 文件要求,WAV文件去掉头部44Byte */ 20 | /* 可使用 https://audio.online-convert.com/convert-to-wav 讲MP3转为WAV*/ 21 | /* 选项设置为 16Bit, 16000Hz, Mono */ 22 | uint8_t (*play)(audio_t *audio, uint8_t *audio_buf, uint32_t audio_len); 23 | 24 | } audio_t; 25 | 26 | uint8_t audio_init(audio_type type); 27 | 28 | uint8_t audio_play(uint8_t *audio_buf, uint32_t audio_len); 29 | 30 | #endif /* __AUDIO_H */ 31 | -------------------------------------------------------------------------------- /components/drivers/audio/pt8211/include/audio_mic.h: -------------------------------------------------------------------------------- 1 | // #ifndef __AUDIO_MIC_H 2 | // #define __AUDIO_MIC_H 3 | 4 | // #include 5 | 6 | // #include "dmac.h" 7 | // #include "i2s.h" 8 | 9 | // #define MIC_I2S_IN_D0 20 10 | // #define MIC_I2S_WS 19 11 | // #define MIC_I2S_SCLK 18 12 | 13 | // #define MIC_I2S_DEVICE I2S_DEVICE_0 14 | // #define MIC_I2S_CHANNEL I2S_CHANNEL_0 15 | // #define MIC_DMAC_CHANNEL DMAC_CHANNEL3 16 | 17 | // #define MIC_SAMPLE_RATE (16000) 18 | // #define MIC_FRAME_LENGTH (512) 19 | 20 | // typedef enum _audio_recv_mode_t{ 21 | // RECV_MODE_ALWAYS, 22 | // RECV_MODE_TIMING, 23 | // } audio_recv_mode_t; 24 | 25 | // typedef enum _audio_recv_state_t{ 26 | // RECV_STATE_IDLE, 27 | // RECV_STATE_RECVING, 28 | // RECV_STATE_READY, 29 | // } audio_recv_state_t; 30 | 31 | // typedef struct _audio_mic_t 32 | // { 33 | // audio_recv_mode_t recv_mode; 34 | // audio_recv_state_t recv_state; 35 | // uint8_t mic_recv_buf_index; 36 | 37 | // uint32_t sample_rate; 38 | // uint16_t recv_frame_length; 39 | // int16_t *recv_buffer; 40 | // uint64_t recv_buffer_length; 41 | // uint16_t recv_buffer_frames; 42 | // uint32_t recv_time_ms; 43 | // uint32_t recv_time_frames; 44 | 45 | // i2s_device_number_t i2s_device_num; 46 | // i2s_channel_num_t i2s_channel_num; 47 | // dmac_channel_number_t dmac_channel; 48 | // } audio_mic_t; 49 | 50 | // extern audio_mic_t audio_mic; 51 | 52 | // void audio_mic_init(); 53 | // void audio_mic_deinit(); 54 | 55 | // void audio_mic_set_sample_rate(uint32_t sample_rate); 56 | // void audio_mic_set_mode(audio_recv_mode_t mode); 57 | // void audio_mic_set_timing_mode_time(uint32_t ms); 58 | // void audio_mic_set_buffer(int16_t *buf, uint64_t length); 59 | // void audio_mic_set_flash_address(uint32_t address, uint64_t length); 60 | 61 | // uint32_t audio_mic_get_sample_rate(); 62 | // audio_recv_mode_t audio_mic_get_mode(); 63 | // audio_recv_state_t audio_mic_get_state(); 64 | // uint32_t audio_mic_get_timing_mode_time(); 65 | 66 | // void audio_mic_start(); 67 | // void audio_mic_stop(); 68 | // void audio_mic_clear(); 69 | 70 | // void audio_mic_save_to_flash(uint32_t addr, int16_t* save_buf, uint32_t length); 71 | 72 | 73 | // #endif -------------------------------------------------------------------------------- /components/drivers/audio/pt8211/include/audio_speaker.h: -------------------------------------------------------------------------------- 1 | #ifndef __AUDIO_SPEAKER_H 2 | #define __AUDIO_SPEAKER_H 3 | 4 | #include 5 | 6 | #include "dmac.h" 7 | #include "i2s.h" 8 | #include "timer.h" 9 | 10 | #include "audio.h" 11 | 12 | // #define SPEAKER_I2S_OUT_D1 18 13 | // #define SPEAKER_I2S_SCLK 35 14 | // #define SPEAKER_I2S_WS 33 15 | 16 | // #define SPEAKER_PA_PIN 11 17 | // #define SPEAKER_PA_IO_NUM 20 18 | 19 | #define SPEAKER_I2S_DEVICE I2S_DEVICE_2 20 | #define SPEAKER_I2S_CHANNEL I2S_CHANNEL_1 21 | #define SPEAKER_DMAC_CHANNEL DMAC_CHANNEL4 22 | #define SPEAKER_TIMER_DEVICE TIMER_DEVICE_0 23 | #define SPEAKER_TIMER_CHANNEL TIMER_CHANNEL_0 24 | 25 | #define SPEAKER_SAMPLE_RATE (16000) 26 | #define SPEAKER_FRAME_LENGTH (512) 27 | 28 | /* 29 | typedef enum _audio_play_mode_t 30 | { 31 | PLAY_MODE_ONCE, 32 | PLAY_MODE_LOOP, 33 | PLAY_MODE_TIMING 34 | } audio_play_mode_t; 35 | 36 | typedef enum _audio_play_state_t 37 | { 38 | PLAY_STATE_STOP, 39 | PLAY_STATE_PLAYING, 40 | PLAY_STATE_PAUSE, 41 | } audio_play_state_t; 42 | 43 | typedef enum _audio_play_volume_level_t 44 | { 45 | PLAY_VOLUME_LEVEL_0, 46 | PLAY_VOLUME_LEVEL_25, 47 | PLAY_VOLUME_LEVEL_50, 48 | PLAY_VOLUME_LEVEL_75, 49 | PLAY_VOLUME_LEVEL_100, 50 | PLAY_VOLUME_LEVEL_125, 51 | PLAY_VOLUME_LEVEL_150, 52 | PLAY_VOLUME_LEVEL_175, 53 | PLAY_VOLUME_LEVEL_200, 54 | } audio_play_volume_level_t; 55 | 56 | typedef struct _audio_speaker_t 57 | { 58 | float volume; 59 | uint8_t ispaly; 60 | audio_play_mode_t play_mode; 61 | audio_play_state_t play_state; 62 | 63 | uint32_t sample_rate; 64 | uint16_t play_frame_length; 65 | uint16_t current_frame; 66 | int16_t *play_buffer; 67 | uint64_t play_buffer_length; 68 | uint16_t play_buffer_frames; 69 | uint32_t play_time_ms; 70 | uint32_t play_time_frame; 71 | 72 | i2s_device_number_t i2s_device_num; 73 | i2s_channel_num_t i2s_channel_num; 74 | dmac_channel_number_t dmac_channel; 75 | timer_device_number_t timer_device; 76 | timer_channel_number_t timer_channel; 77 | 78 | } audio_speaker_t; 79 | 80 | extern audio_speaker_t audio_speaker; 81 | 82 | uint8_t audio_speaker_init(void); 83 | void audio_speaker_deinit(); 84 | 85 | void audio_speaker_set_sample_rate(uint32_t sample_rate); 86 | void audio_speaker_set_mode(audio_play_mode_t mode); 87 | void audio_speaker_set_timing_mode_time(uint32_t ms); 88 | void audio_speaker_set_buffer(int16_t *buf, uint64_t length); 89 | void audio_speaker_set_volume(audio_play_volume_level_t level); 90 | 91 | uint32_t audio_speaker_get_sample_rate(); 92 | audio_play_mode_t audio_speaker_get_mode(); 93 | audio_play_state_t audio_speaker_get_state(); 94 | uint32_t audio_speaker_get_timing_mode_time(); 95 | float audio_speaker_get_volume(); 96 | 97 | void audio_speaker_play(); 98 | void audio_speaker_pause(); 99 | void audio_speaker_resume(); 100 | void audio_speaker_stop(); 101 | void audio_speaker_replay(); 102 | 103 | int16_t *audio_speaker_read_from_flash(uint32_t addr, uint32_t length); 104 | void audio_speaker_free_buf(int16_t *buf); 105 | */ 106 | 107 | uint8_t audio_pt8211_init(audio_t *audio); 108 | 109 | #endif -------------------------------------------------------------------------------- /components/drivers/audio/src/audio.c: -------------------------------------------------------------------------------- 1 | #include "audio.h" 2 | 3 | #include "printf.h" 4 | 5 | #include "music_play.h" 6 | #include "audio_speaker.h" 7 | 8 | #include "global_config.h" 9 | 10 | static audio_t _audio; 11 | 12 | uint8_t audio_play(uint8_t *audio_buf, uint32_t audio_len) 13 | { 14 | if (_audio.play) 15 | { 16 | return _audio.play(&_audio, audio_buf, audio_len); 17 | } 18 | return 0xff; 19 | } 20 | 21 | uint8_t audio_init(audio_type type) 22 | { 23 | switch (type) 24 | { 25 | #if CONFIG_SPK_TYPE_ES8374 26 | case AUDIO_TYPE_ES8374: 27 | { 28 | printk("AUDIO_TYPE_ES8374\r\n"); 29 | audio_es8374_init(&_audio); 30 | } 31 | break; 32 | #endif /* CONFIG_SPK_TYPE_ES8374 */ 33 | #if CONFIG_SPK_TYPE_PT8211 34 | case AUDIO_TYPE_PT8211: 35 | { 36 | printk("AUDIO_TYPE_PT8211\r\n"); 37 | audio_pt8211_init(&_audio); 38 | } 39 | break; 40 | #endif /* CONFIG_SPK_TYPE_PT8211 */ 41 | default: 42 | printk("AUDIO_TYPE_UNK\r\n"); 43 | break; 44 | } 45 | 46 | if (_audio.config) 47 | { 48 | return _audio.config(); 49 | } 50 | 51 | return 0xff; 52 | } -------------------------------------------------------------------------------- /components/drivers/camera/Kconfig: -------------------------------------------------------------------------------- 1 | 2 | menu "Camera( Sensor ) configuration" 3 | 4 | comment "!!!DONT MODIFY CAMERA_RESOLUTION!!!" 5 | 6 | config ENABLE_CAMERA 7 | bool "enable camera" 8 | default y 9 | 10 | choice CAMERA_TYPE 11 | depends on ENABLE_CAMERA 12 | bool "Camera type" 13 | default CAMERA_GC0328_DUAL 14 | 15 | config CAMERA_OV2640 16 | bool "single ov2640" 17 | select NOT_MF1_BOARD 18 | config CAMERA_GC0328_SINGLE 19 | bool "single gc0328" 20 | config CAMERA_GC0328_DUAL 21 | bool "dual gc0328, IR+RGB" 22 | endchoice 23 | 24 | config CAMERA_RESOLUTION_WIDTH 25 | depends on ENABLE_CAMERA 26 | int "Camera resolution width" 27 | default 320 28 | config CAMERA_RESOLUTION_HEIGHT 29 | depends on ENABLE_CAMERA 30 | int "Camera resolution height" 31 | default 240 32 | endmenu 33 | -------------------------------------------------------------------------------- /components/drivers/camera/include/camera.h: -------------------------------------------------------------------------------- 1 | #ifndef __CAMERA_H 2 | #define __CAMERA_H 3 | 4 | #include "stdint.h" 5 | 6 | typedef enum _camera_type 7 | { 8 | CAM_OV2640 = 0, 9 | CAM_GC0328_SINGLE, 10 | CAM_GC0328_DUAL, 11 | } camera_type_t; 12 | 13 | typedef struct _camera camera_t; 14 | typedef struct _camera 15 | { 16 | uint8_t slv_id; 17 | 18 | int (*camera_config)(camera_t *camera); 19 | int (*camera_set_hmirror)(camera_t *camera, uint8_t val); 20 | int (*camera_set_vflip)(camera_t *camera, uint8_t val); 21 | int (*camera_read_id)(camera_t *camera, uint16_t *manuf_id, uint16_t *device_id); 22 | 23 | //only GC0328_DUAL support 24 | int (*camera_modify_reg)(camera_t *camera, uint8_t reg_data[][2]); 25 | } camera_t; 26 | 27 | int camera_init(camera_type_t type); 28 | 29 | int camera_read_id(uint16_t *manuf_id, uint16_t *device_id); 30 | int camera_set_hmirror(uint8_t val); 31 | int camera_set_vflip(uint8_t val); 32 | int camera_config(void); 33 | 34 | int camera_modify_reg(uint8_t reg_data[][2]); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /components/drivers/camera/ov2640/include/ov2640.h: -------------------------------------------------------------------------------- 1 | #ifndef _OV2640_H 2 | #define _OV2640_H 3 | 4 | #include 5 | 6 | #include "camera.h" 7 | 8 | int ov2640_init(camera_t *camera); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /components/drivers/camera/src/camera.c: -------------------------------------------------------------------------------- 1 | #include "camera.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "global_config.h" 7 | 8 | #if CONFIG_CAMERA_OV2640 9 | #include "ov2640.h" 10 | #endif 11 | 12 | static camera_t camera = { 13 | .slv_id = 0x0, 14 | 15 | .camera_config = NULL, 16 | .camera_set_hmirror = NULL, 17 | .camera_set_vflip = NULL, 18 | .camera_read_id = NULL, 19 | }; 20 | 21 | int camera_read_id(uint16_t *manuf_id, uint16_t *device_id) 22 | { 23 | if (camera.camera_read_id) 24 | { 25 | return camera.camera_read_id(&camera, manuf_id, device_id); 26 | } 27 | return 1; 28 | } 29 | 30 | int camera_set_hmirror(uint8_t val) 31 | { 32 | printf("camera_set_hmirror: %d\r\n", val); 33 | 34 | if (camera.camera_set_hmirror) 35 | { 36 | return camera.camera_set_hmirror(&camera, val); 37 | } 38 | 39 | return 1; 40 | } 41 | 42 | int camera_set_vflip(uint8_t val) 43 | { 44 | printf("camera_set_vflip: %d\r\n", val); 45 | 46 | if (camera.camera_set_vflip) 47 | { 48 | return camera.camera_set_vflip(&camera, val); 49 | } 50 | return 1; 51 | } 52 | 53 | int camera_config(void) 54 | { 55 | if (camera.camera_config) 56 | { 57 | return camera.camera_config(&camera); 58 | } 59 | return 1; 60 | } 61 | 62 | int camera_modify_reg(uint8_t reg_data[][2]) 63 | { 64 | if (camera.camera_modify_reg) 65 | { 66 | return camera.camera_modify_reg(&camera, reg_data); 67 | } 68 | return 1; 69 | } 70 | 71 | /////////////////////////////////////////////////////////////////////////////// 72 | /* 具体函数在工程中,这里只是防止编译出错 */ 73 | int __attribute__((weak)) gc0328_dual_init(camera_t *camera) 74 | { 75 | printf("error at %s %s->%d\r\n", __FILE__, __func__, __LINE__); 76 | while (1) 77 | ; 78 | return 0; 79 | } 80 | 81 | int __attribute__((weak)) gc0328_single_init(camera_t *camera) 82 | { 83 | printf("error at %s %s->%d\r\n", __FILE__, __func__, __LINE__); 84 | while (1) 85 | ; 86 | return 0; 87 | } 88 | 89 | /////////////////////////////////////////////////////////////////////////////// 90 | 91 | int camera_init(camera_type_t type) 92 | { 93 | switch (type) 94 | { 95 | #if CONFIG_CAMERA_OV2640 96 | case CAM_OV2640: 97 | { 98 | ov2640_init(&camera); 99 | } 100 | break; 101 | #endif 102 | #if (CONFIG_CAMERA_GC0328_SINGLE || CONFIG_CAMERA_GC0328_DUAL) 103 | case CAM_GC0328_SINGLE: 104 | { 105 | gc0328_single_init(&camera); 106 | } 107 | break; 108 | case CAM_GC0328_DUAL: 109 | { 110 | gc0328_dual_init(&camera); 111 | } 112 | break; 113 | #endif 114 | default: 115 | { 116 | printf("unknown camera type !!!\r\n"); 117 | return 1; 118 | } 119 | break; 120 | } 121 | /* config camera */ 122 | camera.camera_config(&camera); 123 | return 0; 124 | } 125 | -------------------------------------------------------------------------------- /components/drivers/lcd/Kconfig: -------------------------------------------------------------------------------- 1 | 2 | menu "LCD configuration" 3 | 4 | config ENABLE_LCD 5 | bool "enable lcd" 6 | default y 7 | 8 | choice LCD_TYPE 9 | depends on ENABLE_LCD 10 | 11 | bool "LCD driver type" 12 | default LCD_TYPE_ST7789 13 | 14 | config LCD_TYPE_ST7789 15 | bool "LCD use ST7789" 16 | config LCD_TYPE_SIPEED 17 | bool "LCD use sipeed board, not support now" 18 | endchoice 19 | 20 | menu "Lcd ( Display ) configuration" 21 | depends on ENABLE_LCD 22 | 23 | config LCD_WIDTH 24 | depends on LCD_TYPE_ST7789 25 | int "Lcd display size width" 26 | default 240 27 | config LCD_HEIGHT 28 | depends on LCD_TYPE_ST7789 29 | int "Lcd display size height" 30 | default 240 31 | 32 | config LCD_CLK_FREQ_MHZ 33 | depends on LCD_TYPE_ST7789 34 | int "lcd clk frequency MHZ" 35 | default 15 36 | endmenu 37 | 38 | menu "LCD Pin configuration" 39 | depends on ENABLE_LCD 40 | 41 | config PIN_NUM_LCD_RST 42 | int "LCD Pin RST" 43 | default 37 44 | config PIN_NUM_LCD_DCX 45 | int "LCD Pin DCX" 46 | default 38 47 | config PIN_NUM_LCD_WRX 48 | int "LCD Pin WRX" 49 | default 36 50 | config PIN_NUM_LCD_SCK 51 | int "LCD Pin SCK" 52 | default 39 53 | endmenu 54 | 55 | menu "LCD Pin Func configuration" 56 | depends on ENABLE_LCD 57 | 58 | config GPIOHS_NUM_LCD_DCX 59 | int "LCD Pin DCX bind with GPIOHS num" 60 | default 0 61 | config GPIOHS_NUM_LCD_RST 62 | int "LCD Pin RST bind with GPIOHS num" 63 | default 1 64 | endmenu 65 | 66 | endmenu 67 | -------------------------------------------------------------------------------- /components/drivers/lcd/include/lcd.h: -------------------------------------------------------------------------------- 1 | #ifndef __LCD_H 2 | #define __LCD_H 3 | 4 | #include "stdint.h" 5 | 6 | /* clang-format off */ 7 | 8 | //RGB565 color 9 | #define BLACK 0x0000 10 | #define NAVY 0x000F 11 | #define DARKGREEN 0x03E0 12 | #define DARKCYAN 0x03EF 13 | #define MAROON 0x7800 14 | #define PURPLE 0x780F 15 | #define OLIVE 0x7BE0 16 | #define LIGHTGREY 0xC618 17 | #define DARKGREY 0x7BEF 18 | #define BLUE 0x001F 19 | #define GREEN 0x07E0 20 | #define CYAN 0x07FF 21 | #define RED 0xF800 22 | #define MAGENTA 0xF81F 23 | #define YELLOW 0xFFE0 24 | #define WHITE 0xFFFF 25 | #define ORANGE 0xFD20 26 | #define GREENYELLOW 0xAFE5 27 | #define PINK 0xF81F 28 | #define USER_COLOR 0xAA55 29 | /* clang-format on */ 30 | 31 | typedef enum _lcd_type 32 | { 33 | LCD_ST7789 = 0, 34 | LCD_SIPEED = 1, 35 | } lcd_type_t; 36 | 37 | typedef enum _lcd_dir 38 | { 39 | DIR_XY_RLUD = 0x00, 40 | DIR_YX_RLUD = 0x20, 41 | DIR_XY_LRUD = 0x40, 42 | DIR_YX_LRUD = 0x60, 43 | DIR_XY_RLDU = 0x80, 44 | DIR_YX_RLDU = 0xA0, 45 | DIR_XY_LRDU = 0xC0, 46 | DIR_YX_LRDU = 0xE0, 47 | DIR_XY_MASK = 0x20, 48 | DIR_MASK = 0xE0, 49 | } lcd_dir_t; 50 | 51 | typedef struct _lcd lcd_t; 52 | typedef struct _lcd 53 | { 54 | uint8_t dir; 55 | uint16_t width; 56 | uint16_t height; 57 | 58 | int (*lcd_config)(lcd_t *lcd); 59 | int (*lcd_clear)(lcd_t *lcd, uint16_t rgb565_color); 60 | int (*lcd_set_direction)(lcd_t *lcd, lcd_dir_t dir); 61 | 62 | int (*lcd_set_area)(lcd_t *lcd, uint16_t x, uint16_t y, uint16_t w, 63 | uint16_t h); 64 | 65 | int (*lcd_draw_picture)(lcd_t *lcd, uint16_t x, uint16_t y, uint16_t w, 66 | uint16_t h, uint32_t *imamge); 67 | } lcd_t; 68 | 69 | int lcd_init(lcd_type_t lcd_type); 70 | 71 | int lcd_config(void); 72 | int lcd_clear(uint16_t rgb565_color); 73 | int lcd_set_direction(lcd_dir_t dir); 74 | 75 | int lcd_set_area(uint16_t x, uint16_t y, uint16_t w, uint16_t h); 76 | 77 | int lcd_draw_picture(uint16_t x, uint16_t y, uint16_t w, uint16_t h, 78 | uint32_t *imamge); 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /components/drivers/lcd/lcd_sipeed/include/lcd_sipeed.h: -------------------------------------------------------------------------------- 1 | #ifndef __LCD_SPIEED_H 2 | #define __LCD_SPIEED_H 3 | 4 | #include 5 | 6 | #include "spi.h" 7 | 8 | /* clang-format off */ 9 | #define LCD_BL_ON (0x61) 10 | #define LCD_BL_OFF (0x60) 11 | #define LCD_DISOLAY_ON (0x30) 12 | #define LCD_FRAME_START (0x41) 13 | 14 | #define LCDDisMode_normal (0x01) 15 | #define LCDDisMode_TranBK (0x00) 16 | #define LCDDisMode_Reverse (0x10) 17 | 18 | #define LCD_SIPEED_SPI_DEV (SPI_DEVICE_0) 19 | #define LCD_SIPEED_SPI_SS (SPI_CHIP_SELECT_3) 20 | #define LCD_SIPEED_SPI_FREQ (35000000) 21 | 22 | #define LCD_SIPEED_FRAME_END_LINE (LCD_H * 2 + 63 - 1) 23 | /* clang-format on */ 24 | 25 | extern volatile uint8_t dis_flag; 26 | 27 | void lcd_init(void); 28 | 29 | void LCDPrintStr(uint8_t *img, uint16_t XPos, uint16_t YPos, char *Srt, 30 | uint8_t Mode, uint16_t FontColor, uint16_t BKColor); 31 | 32 | uint8_t lcd_covert_cam_order(uint32_t *addr, uint32_t length); 33 | 34 | void copy_image_cma_to_lcd(uint8_t *cam_img, uint8_t *lcd_img); 35 | 36 | /* flush img_buf to lcd */ 37 | void lcd_sipeed_display(uint8_t *img_buf, uint8_t block); 38 | 39 | #endif -------------------------------------------------------------------------------- /components/drivers/lcd/lcd_st7789/include/lcd_st7789.h: -------------------------------------------------------------------------------- 1 | #ifndef _LCD_ST7789_H_ 2 | #define _LCD_ST7789_H_ 3 | 4 | #include 5 | #include "lcd.h" 6 | 7 | int lcd_st7789_init(lcd_t *lcd); 8 | 9 | #endif -------------------------------------------------------------------------------- /components/drivers/lcd/lcd_st7789/include/nt35310.h: -------------------------------------------------------------------------------- 1 | #ifndef _NT35310_H_ 2 | #define _NT35310_H_ 3 | 4 | #include 5 | 6 | void tft_hard_init(void); 7 | void tft_write_command(uint8_t cmd); 8 | void tft_write_byte(uint8_t *data_buf, uint32_t length); 9 | void tft_write_half(uint16_t *data_buf, uint32_t length); 10 | void tft_write_word(uint32_t *data_buf, uint32_t length, uint32_t flag); 11 | void tft_fill_data(uint32_t *data_buf, uint32_t length); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /components/drivers/lcd/src/lcd.c: -------------------------------------------------------------------------------- 1 | #include "lcd.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "global_config.h" 7 | 8 | #if CONFIG_LCD_TYPE_ST7789 9 | #include "lcd_st7789.h" 10 | #endif 11 | 12 | static lcd_t lcd = { 13 | .dir = 0x0, 14 | .width = 0, 15 | .height = 0, 16 | 17 | .lcd_config = NULL, 18 | .lcd_clear = NULL, 19 | .lcd_set_direction = NULL, 20 | .lcd_set_area = NULL, 21 | .lcd_draw_picture = NULL, 22 | }; 23 | 24 | int lcd_set_direction(lcd_dir_t dir) 25 | { 26 | printf("lcd_set_direction: %02X\r\n", dir); 27 | 28 | if (lcd.lcd_set_direction) 29 | { 30 | lcd.lcd_set_direction(&lcd, dir); 31 | return 0; 32 | } 33 | return 1; 34 | } 35 | 36 | int lcd_set_area(uint16_t x, uint16_t y, 37 | uint16_t w, uint16_t h) 38 | { 39 | if (lcd.lcd_set_area) 40 | { 41 | lcd.lcd_set_area(&lcd, x, y, w, h); 42 | return 0; 43 | } 44 | return 1; 45 | } 46 | 47 | int lcd_draw_picture(uint16_t x, uint16_t y, 48 | uint16_t w, uint16_t h, 49 | uint32_t *imamge) 50 | { 51 | if (lcd.lcd_draw_picture) 52 | { 53 | lcd.lcd_draw_picture(&lcd, x, y, w, h, imamge); 54 | return 0; 55 | } 56 | return 1; 57 | } 58 | 59 | int lcd_clear(uint16_t rgb565_color) 60 | { 61 | if (lcd.lcd_clear) 62 | { 63 | lcd.lcd_clear(&lcd, rgb565_color); 64 | return 0; 65 | } 66 | return 1; 67 | } 68 | 69 | int lcd_init(lcd_type_t lcd_type) 70 | { 71 | switch (lcd_type) 72 | { 73 | #if CONFIG_LCD_TYPE_ST7789 74 | case LCD_ST7789: 75 | { 76 | lcd_st7789_init(&lcd); 77 | lcd.lcd_config(&lcd); 78 | return 0; 79 | } 80 | break; 81 | #endif 82 | case LCD_SIPEED: 83 | default: 84 | break; 85 | } 86 | return 1; 87 | } 88 | -------------------------------------------------------------------------------- /components/drivers/mem_macro/mem_macro.h: -------------------------------------------------------------------------------- 1 | #ifndef __MEM_MACRO_H 2 | #define __MEM_MACRO_H 3 | 4 | #include 5 | 6 | /* clang-format off */ 7 | /////////////////////////////////////////////////////////////////////////////// 8 | #define _IS_IOMEM(x) (!((uint64_t)(&(x))&0x80000000)) 9 | #define _IS_CACHEMEM(x) ((uint64_t)(&(x))&0x80000000) 10 | #define _IS_IOMEMP(x) (!((uint64_t)(x)&0x80000000)) 11 | #define _IS_CACHEMEMP(x) ((uint64_t)(x)&0x80000000) 12 | 13 | #define _IOMEM(x, type) (*(type *)(((uint64_t)&(x))-0x40000000)) 14 | #define _IOMEM_UINT8(x) (*(uint8_t *)(((uint64_t)&(x))-0x40000000)) 15 | #define _IOMEM_ADDR(x) (_IS_IOMEM(x)?(uint64_t)(x):(((uint64_t)&(x))-0x40000000)) 16 | #define _IOMEM_PADDR(p) (_IS_IOMEMP(p)?(uint64_t)(p):(((uint64_t)(p))-0x40000000)) 17 | #define _ADDR(x) ((uint64_t)(x)) 18 | #define _IN_BUF(x, buf) (_ADDR(x)>=_ADDR(buf) && _ADDR(x)<_ADDR(buf)+sizeof(buf)) 19 | #define CHECK_IOMEM(x) configASSERT(_IS_IOMEM(x)) 20 | #define CHECK_IOMEMP(x) configASSERT(_IS_IOMEMP(x)) 21 | 22 | #define _MODULE_ADDR(x) (x) 23 | 24 | #define _CACHE_ADDR(x) (_IS_CACHEMEM(x)?(uint64_t)(x):(((uint64_t)&(x))+0x40000000)) 25 | #define _CACHE_PADDR(p) (_IS_CACHEMEMP(p)?(uint64_t)(p):(((uint64_t)(p))+0x40000000)) 26 | 27 | /////////////////////////////////////////////////////////////////////////////// 28 | 29 | #endif /* __MEM_MARCO_H */ 30 | -------------------------------------------------------------------------------- /components/drivers/rtc/Kconfig: -------------------------------------------------------------------------------- 1 | menu "RTC configuration" 2 | 3 | config ENABLE_RTC 4 | bool "enable rtc" 5 | default n 6 | 7 | choice RTC_TYPE 8 | depends on ENABLE_RTC 9 | bool "RTC Type" 10 | default RTC_TYPE_BM8563 11 | 12 | config RTC_TYPE_GM1302 13 | bool "rtc use gm1302" 14 | 15 | config RTC_TYPE_BM8563 16 | bool "rtc use bm8563" 17 | endchoice 18 | 19 | menu "GM1302 Pin configuration" 20 | depends on RTC_TYPE_GM1302 21 | 22 | config PIN_NUM_RTC_GM1302_RST 23 | int "RTC GM1302 Pin RST" 24 | default 11 25 | config PIN_NUM_RTC_GM1302_DAT 26 | int "RTC GM1302 Pin DAT" 27 | default 13 28 | config PIN_NUM_RTC_GM1302_CLK 29 | int "RTC GM1302 Pin CLK" 30 | default 12 31 | endmenu 32 | 33 | menu "GM1302 Pin Func configuration" 34 | depends on RTC_TYPE_GM1302 35 | config GPIOHS_NUM_RTC_GM1302_RST 36 | int "RTC GM1302 GPIOHS RST num" 37 | default 17 38 | config GPIOHS_NUM_RTC_GM1302_DAT 39 | int "RTC GM1302 GPIOHS DAT num" 40 | default 18 41 | config GPIOHS_NUM_RTC_GM1302_CLK 42 | int "RTC GM1302 GPIOHS CLK num" 43 | default 19 44 | endmenu 45 | 46 | menu "RTC BM8563 Pin configuration" 47 | depends on RTC_TYPE_BM8563 48 | config PIN_NUM_RTC_BM8563_SDA 49 | int "RTC BM8563 Pin SDA" 50 | default 31 51 | config PIN_NUM_RTC_BM8563_SCL 52 | int "RTC BM8563 Pin SCL" 53 | default 30 54 | endmenu 55 | 56 | menu "RTC BM8563 Pin Func configuration" 57 | depends on RTC_TYPE_BM8563 58 | config GPIOHS_NUM_RTC_BM8563_SDA 59 | int "RTC BM8563 GPIOHS SDA" 60 | default 17 61 | config GPIOHS_NUM_RTC_BM8563_SCL 62 | int "RTC BM8563 GPIOHS SCL" 63 | default 18 64 | endmenu 65 | endmenu -------------------------------------------------------------------------------- /components/drivers/rtc/bm8563/include/bm8563.h: -------------------------------------------------------------------------------- 1 | #ifndef __BM8563_H 2 | #define __BM8563_H 3 | 4 | #include 5 | 6 | #include "sipeed_rtc.h" 7 | 8 | uint8_t rtc_bm8563_init(sipeed_rtc_t *rtc); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /components/drivers/rtc/gm1302/include/gm1302.h: -------------------------------------------------------------------------------- 1 | #ifndef __GM1302_H 2 | #define __GM1302_H 3 | 4 | #include 5 | #include 6 | 7 | #include "sipeed_rtc.h" 8 | 9 | /* read: REG|0x01, write: REG|0x00 */ 10 | typedef enum gm1302_reg 11 | { 12 | GM1302_REG_WRITE = 0x0, 13 | GM1302_REG_READ = 0x1, 14 | 15 | GM1302_REG_SEC = 0x80, 16 | GM1302_REG_MIN = 0x80 | (1 << 1), 17 | GM1302_REG_HOUR = 0x80 | (2 << 1), 18 | GM1302_REG_MDAY = 0x80 | (3 << 1), 19 | GM1302_REG_MON = 0x80 | (4 << 1), 20 | GM1302_REG_YEAR = 0x80 | (5 << 1), 21 | GM1302_REG_WDAY = 0x80 | (6 << 1), 22 | GM1302_REG_WP = 0x80 | (7 << 1), 23 | GM1302_REG_CHARGE = 0x80 | (8 << 1), 24 | GM1302_REG_MULTIBYTE = 0x80 | (0x1F << 1), 25 | }; 26 | 27 | void gm1302_enable_crystal(void); 28 | 29 | uint8_t gm1302_set_charge(uint8_t diode_num, uint8_t res_val); 30 | 31 | uint8_t rtc_gm1302_init(sipeed_rtc_t *rtc); 32 | 33 | #endif /* __GM1302_H */ -------------------------------------------------------------------------------- /components/drivers/rtc/include/sipeed_rtc.h: -------------------------------------------------------------------------------- 1 | #ifndef __SIPEED_RTC_H 2 | #define __SIPEED_RTC_H 3 | 4 | #include 5 | 6 | #define RTC_BASE_YEAR (2000) 7 | 8 | typedef enum 9 | { 10 | RTC_TYPE_GM1302 = 0, 11 | RTC_TYPE_BM8563 = 1, 12 | RTC_TYPE_MAX, 13 | } rtc_type; 14 | 15 | struct sipeed_rtc_time 16 | { 17 | uint8_t tm_sec; /* 秒, 取值区间为[0,59] */ 18 | uint8_t tm_min; /* 分, 取值区间为[0,59] */ 19 | uint8_t tm_hour; /* 时, 取值区间为[01,12] / [0,23] */ 20 | uint8_t tm_mday; /* 日, 取值区间为[0,28 / 29] / [1,30] / [1,31] */ 21 | uint8_t tm_mon; /* 月, 取值区间为[1,12] */ 22 | uint8_t tm_wday; /* 周, 取值区间为[1,7] */ 23 | uint16_t tm_year; /* 年, 取值区间为[00,99] */ 24 | }; 25 | 26 | typedef struct _sipeed_rtc sipeed_rtc_t; 27 | typedef struct _sipeed_rtc 28 | { 29 | uint8_t (*config)(void); 30 | 31 | uint8_t (*read_time)(sipeed_rtc_t *rtc, struct sipeed_rtc_time *time); 32 | 33 | uint8_t (*write_time)(sipeed_rtc_t *rtc, struct sipeed_rtc_time *time); 34 | 35 | } sipeed_rtc_t; 36 | 37 | uint8_t sipeed_rtc_init(rtc_type type); 38 | 39 | uint8_t sipeed_rtc_read_time(struct sipeed_rtc_time *time); 40 | 41 | uint8_t sipeed_rtc_write_time(struct sipeed_rtc_time *time); 42 | 43 | #endif /* __SIPEED_RTC_H */ 44 | -------------------------------------------------------------------------------- /components/drivers/rtc/src/sipeed_rtc.c: -------------------------------------------------------------------------------- 1 | #include "sipeed_rtc.h" 2 | 3 | #include "bm8563.h" 4 | #include "gm1302.h" 5 | 6 | #include "printf.h" 7 | 8 | #include "global_config.h" 9 | 10 | static sipeed_rtc_t _sipeed_rtc = { 11 | .config = NULL, 12 | .read_time = NULL, 13 | .write_time = NULL, 14 | }; 15 | 16 | uint8_t sipeed_rtc_read_time(struct sipeed_rtc_time *time) 17 | { 18 | if (_sipeed_rtc.read_time) 19 | { 20 | return _sipeed_rtc.read_time(&_sipeed_rtc, time); 21 | } 22 | return 0xFF; 23 | } 24 | 25 | uint8_t sipeed_rtc_write_time(struct sipeed_rtc_time *time) 26 | { 27 | if (_sipeed_rtc.write_time) 28 | { 29 | return _sipeed_rtc.write_time(&_sipeed_rtc, time); 30 | } 31 | return 0xFF; 32 | } 33 | 34 | uint8_t sipeed_rtc_init(rtc_type type) 35 | { 36 | switch (type) 37 | { 38 | #if CONFIG_RTC_TYPE_GM1302 39 | case RTC_TYPE_GM1302: 40 | { 41 | printk("RTC_TYPE_GM1302\r\n"); 42 | rtc_gm1302_init(&_sipeed_rtc); 43 | } 44 | break; 45 | #endif /* CONFIG_RTC_TYPE_GM1302 */ 46 | #if CONFIG_RTC_TYPE_BM8563 47 | case RTC_TYPE_BM8563: 48 | { 49 | printk("RTC_TYPE_BM8563\r\n"); 50 | rtc_bm8563_init(&_sipeed_rtc); 51 | } 52 | break; 53 | #endif /* CONFIG_RTC_TYPE_BM8563 */ 54 | default: 55 | printk("RTC_TYPE_UNK\r\n"); 56 | break; 57 | } 58 | 59 | if (_sipeed_rtc.config) 60 | { 61 | return _sipeed_rtc.config(); 62 | } 63 | return 0xFF; 64 | } 65 | -------------------------------------------------------------------------------- /components/drivers/sd_card/Kconfig: -------------------------------------------------------------------------------- 1 | 2 | menu "SPI TF card configuration" 3 | 4 | config ENABLE_SD_CARD 5 | bool "Enable SPI TF card" 6 | default n 7 | 8 | menu "SPI TF card configuration" 9 | depends on ENABLE_SD_CARD 10 | 11 | config PIN_NUM_SD_CARD_SCLK 12 | int "SPI TF card SCLK pin number" 13 | default 27 14 | config PIN_NUM_SD_CARD_MOSI 15 | int "SPI TF card MOSI pin number" 16 | default 28 17 | config PIN_NUM_SD_CARD_MISO 18 | int "SPI TF card MISO pin number" 19 | default 26 20 | config PIN_NUM_SD_CARD_CS 21 | int "SPI TF card CS pin number" 22 | default 29 23 | endmenu 24 | 25 | menu "SPI TF card Pin Func configuration" 26 | depends on ENABLE_SD_CARD 27 | 28 | config GPIOHS_NUM_SD_CARD_SCLK 29 | int "SPI TF card GPIOHS simulate SCK number" 30 | default 2 31 | config GPIOHS_NUM_SD_CARD_MOSI 32 | int "SPI TF card GPIOHS simulate MOSI number" 33 | default 3 34 | config GPIOHS_NUM_SD_CARD_MISO 35 | int "SPI TF card GPIOHS simulate MISO number" 36 | default 4 37 | config GPIOHS_NUM_SD_CARD_CS 38 | int "SPI TF card GPIOHS simulate CS number" 39 | default 5 40 | endmenu 41 | endmenu 42 | -------------------------------------------------------------------------------- /components/drivers/sd_card/include/sd_card.h: -------------------------------------------------------------------------------- 1 | #ifndef __SD_CARD_H 2 | #define __SD_CARD_H 3 | 4 | #include "stdint.h" 5 | 6 | /* clang-format off */ 7 | // SD卡类型定义 8 | #define SD_TYPE_ERR (0x00) 9 | #define SD_TYPE_MMC (0x01) 10 | #define SD_TYPE_V1 (0x02) 11 | #define SD_TYPE_V2 (0x04) 12 | #define SD_TYPE_V2HC (0x06) 13 | // SD卡指令表 14 | #define CMD0 (0) //卡复位 15 | #define CMD1 (1) 16 | #define CMD8 (8) //命令8 ,SEND_IF_COND 17 | #define CMD9 (9) //命令9 ,读CSD数据 18 | #define CMD10 (10) //命令10,读CID数据 19 | #define CMD12 (12) //命令12,停止数据传输 20 | #define CMD16 (16) //命令16,设置SectorSize 应返回0x00 21 | #define CMD17 (17) //命令17,读sector 22 | #define CMD18 (18) //命令18,读Multi sector 23 | #define CMD23 (23) //命令23,设置多sector写入前预先擦除N个block 24 | #define CMD24 (24) //命令24,写sector 25 | #define CMD25 (25) //命令25,写Multi sector 26 | #define CMD41 (41) //命令41,应返回0x00 27 | #define CMD55 (55) //命令55,应返回0x01 28 | #define CMD58 (58) //命令58,读OCR信息 29 | #define CMD59 (59) //命令59,使能/禁止CRC,应返回0x00 30 | //数据写入回应字意义 31 | #define MSD_DATA_OK (0x05) 32 | #define MSD_DATA_CRC_ERROR (0x0B) 33 | #define MSD_DATA_WRITE_ERROR (0x0D) 34 | #define MSD_DATA_OTHER_ERROR (0xFF) 35 | //SD卡回应标记字 36 | #define MSD_RESPONSE_NO_ERROR (0x00) 37 | #define MSD_IN_IDLE_STATE (0x01) 38 | #define MSD_ERASE_RESET (0x02) 39 | #define MSD_ILLEGAL_COMMAND (0x04) 40 | #define MSD_COM_CRC_ERROR (0x08) 41 | #define MSD_ERASE_SEQUENCE_ERROR (0x10) 42 | #define MSD_ADDRESS_ERROR (0x20) 43 | #define MSD_PARAMETER_ERROR (0x40) 44 | #define MSD_RESPONSE_FAILURE (0xFF) 45 | /* clang-format on */ 46 | 47 | extern uint8_t SD_Type; //SD卡的类型 48 | 49 | //函数申明区 50 | void SD_SPI_SpeedLow(void); 51 | void SD_SPI_SpeedHigh(void); 52 | uint8_t SD_WaitReady(void); //等待SD卡准备 53 | uint8_t SD_GetResponse(uint8_t Response); //获得相应 54 | uint8_t SD_Initialize(void); //初始化 55 | uint8_t SD_ReadDisk(uint8_t *buf, uint32_t sector, uint8_t cnt); //读块 56 | uint8_t SD_WriteDisk(uint8_t *buf, uint32_t sector, uint8_t cnt); //写块 57 | uint32_t SD_GetSectorCount(void); //读扇区数 58 | uint8_t SD_GetCID(uint8_t *cid_data); //读SD卡CID 59 | uint8_t SD_GetCSD(uint8_t *csd_data); //读SD卡CSD 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /components/kendryte_sdk/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ################# Add include ################# 3 | list(APPEND ADD_INCLUDE 4 | "kendryte-standalone-sdk/lib/bsp/include" 5 | "kendryte-standalone-sdk/lib/drivers/include" 6 | # "kendryte-standalone-sdk/lib/nncase/include" 7 | "kendryte-standalone-sdk/lib/utils/include" 8 | "kendryte-standalone-sdk/third_party/xtl/include" 9 | ) 10 | # list(APPEND ADD_PRIVATE_INCLUDE "include_private") 11 | ############################################### 12 | 13 | ############## Add source files ############### 14 | append_srcs_dir(ADD_SRCS "kendryte-standalone-sdk/lib/bsp") 15 | append_srcs_dir(ADD_SRCS "kendryte-standalone-sdk/lib/drivers") 16 | 17 | # append_srcs_dir(ADD_SRCS "kendryte-standalone-sdk/lib/nncase") 18 | # FILE(GLOB_RECURSE NNCASE_SRC 19 | # "kendryte-standalone-sdk/lib/nncase/*.c" 20 | # "kendryte-standalone-sdk/lib/nncase/*.cpp" 21 | # ) 22 | 23 | append_srcs_dir(ADD_SRCS "src") 24 | set(ADD_ASM_SRCS "kendryte-standalone-sdk/lib/bsp/crt.S") 25 | 26 | # list(APPEND ADD_SRCS ${ADD_ASM_SRCS} ${NNCASE_SRC}) 27 | list(APPEND ADD_SRCS ${ADD_ASM_SRCS} ) 28 | 29 | # list(REMOVE_ITEM COMPONENT_SRCS "src/test.c") 30 | 31 | SET_PROPERTY(SOURCE ${ADD_ASM_SRCS} PROPERTY LANGUAGE C) 32 | SET_SOURCE_FILES_PROPERTIES(${ADD_ASM_SRCS} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp -D __riscv64") 33 | ############################################### 34 | 35 | ###### Add required/dependent components ###### 36 | # list(APPEND ADD_REQUIREMENTS stdc++ m) 37 | list(APPEND ADD_REQUIREMENTS m) 38 | ############################################### 39 | 40 | ############ Add static libs ################## 41 | # list(APPEND ADD_STATIC_LIB "libs/lib_mic.a" 42 | # ) 43 | ############################################### 44 | 45 | list(APPEND ADD_DEFINITIONS -DCONFIG_LOG_LEVEL=${CONFIG_SDK_LOG_LEVEL} 46 | -DNNCASE_TARGET=k210 47 | -DTCB_SPAN_NO_EXCEPTIONS 48 | -DTCB_SPAN_NO_CONTRACT_CHECKING 49 | -DCONFIG_LOG_ENABLE=1 50 | -DCONFIG_LOG_COLORS=1 51 | -DLOG_KERNEL=1 52 | -D__riscv64 53 | ) 54 | 55 | register_component() 56 | 57 | -------------------------------------------------------------------------------- /components/kendryte_sdk/Kconfig: -------------------------------------------------------------------------------- 1 | 2 | menu "Kendryte SDK configurations" 3 | config SDK_LOG_LEVEL 4 | int "log level, 5:LOG_VERBOSE, 4:LOG_DEBUG, 3:LOG_INFO, 2:LOG_WARN, 1:LOG_ERROR, 0:LOG_NONE" 5 | range 0 5 6 | default 5 7 | endmenu 8 | -------------------------------------------------------------------------------- /components/third_party/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if(CONFIG_OOFATFS_ENABLE) 3 | list(APPEND ADD_INCLUDE "oofatfs/include") 4 | 5 | append_srcs_dir(ADD_SRCS "oofatfs/src") 6 | append_srcs_dir(ADD_SRCS "oofatfs/option") 7 | 8 | list(APPEND ADD_REQUIREMENTS kendryte_sdk drivers) 9 | 10 | register_component() 11 | endif() 12 | -------------------------------------------------------------------------------- /components/third_party/Kconfig: -------------------------------------------------------------------------------- 1 | 2 | menu "Third party config" 3 | config OOFATFS_ENABLE 4 | bool "Enbale oofatfs" 5 | default n 6 | select ENABLE_SD_CARD 7 | endmenu 8 | 9 | -------------------------------------------------------------------------------- /components/third_party/oofatfs/include/diskio.h: -------------------------------------------------------------------------------- 1 | /* This file is part of ooFatFs, a customised version of FatFs 2 | * See https://github.com/micropython/oofatfs for details 3 | */ 4 | 5 | /*-----------------------------------------------------------------------/ 6 | / Low level disk interface modlue include file (C)ChaN, 2014 / 7 | /-----------------------------------------------------------------------*/ 8 | 9 | #ifndef _DISKIO_DEFINED 10 | #define _DISKIO_DEFINED 11 | 12 | #include "ff.h" 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | /* Status of Disk Functions */ 19 | typedef BYTE DSTATUS; 20 | 21 | /* Results of Disk Functions */ 22 | typedef enum 23 | { 24 | RES_OK = 0, /* 0: Successful */ 25 | RES_ERROR, /* 1: R/W Error */ 26 | RES_WRPRT, /* 2: Write Protected */ 27 | RES_NOTRDY, /* 3: Not Ready */ 28 | RES_PARERR /* 4: Invalid Parameter */ 29 | } DRESULT; 30 | 31 | /*---------------------------------------*/ 32 | /* Prototypes for disk control functions */ 33 | 34 | DRESULT disk_read(void *drv, BYTE *buff, DWORD sector, UINT count); 35 | DRESULT disk_write(void *drv, const BYTE *buff, DWORD sector, UINT count); 36 | DRESULT disk_ioctl(void *drv, BYTE cmd, void *buff); 37 | 38 | /* Disk Status Bits (DSTATUS) */ 39 | 40 | #define STA_NOINIT 0x01 /* Drive not initialized */ 41 | #define STA_NODISK 0x02 /* No medium in the drive */ 42 | #define STA_PROTECT 0x04 /* Write protected */ 43 | 44 | /* Command code for disk_ioctrl fucntion */ 45 | 46 | /* Generic command (Used by FatFs) */ 47 | #define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */ 48 | #define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */ 49 | #define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */ 50 | #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */ 51 | #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */ 52 | #define IOCTL_INIT 5 53 | #define IOCTL_STATUS 6 54 | 55 | /* Generic command (Not used by FatFs) */ 56 | #define CTRL_POWER 5 /* Get/Set power status */ 57 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */ 58 | #define CTRL_EJECT 7 /* Eject media */ 59 | #define CTRL_FORMAT 8 /* Create physical format on the media */ 60 | 61 | /* MMC/SDC specific ioctl command */ 62 | #define MMC_GET_TYPE 10 /* Get card type */ 63 | #define MMC_GET_CSD 11 /* Get CSD */ 64 | #define MMC_GET_CID 12 /* Get CID */ 65 | #define MMC_GET_OCR 13 /* Get OCR */ 66 | #define MMC_GET_SDSTAT 14 /* Get SD status */ 67 | #define ISDIO_READ 55 /* Read data form SD iSDIO register */ 68 | #define ISDIO_WRITE 56 /* Write data to SD iSDIO register */ 69 | #define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */ 70 | 71 | /* ATA/CF specific ioctl command */ 72 | #define ATA_GET_REV 20 /* Get F/W revision */ 73 | #define ATA_GET_MODEL 21 /* Get model name */ 74 | #define ATA_GET_SN 22 /* Get serial number */ 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /components/third_party/oofatfs/option/unicode.c0: -------------------------------------------------------------------------------- 1 | #include "../ff.h" 2 | 3 | #if _USE_LFN != 0 4 | 5 | #if _CODE_PAGE == 932 /* Japanese Shift_JIS */ 6 | #include "cc932.c" 7 | #elif _CODE_PAGE == 936 /* Simplified Chinese GBK */ 8 | #include "cc936.c" 9 | #elif _CODE_PAGE == 949 /* Korean */ 10 | #include "cc949.c" 11 | #elif _CODE_PAGE == 950 /* Traditional Chinese Big5 */ 12 | #include "cc950.c" 13 | #else /* Single Byte Character-Set */ 14 | #include "ccsbcs.c" 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /components/third_party/oofatfs/src/diskio.c: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------*/ 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2011 */ 3 | /*-----------------------------------------------------------------------*/ 4 | /* This is a stub disk I/O module that acts as front end of the existing */ 5 | /* disk I/O modules and attach it to FatFs module with common interface. */ 6 | /*-----------------------------------------------------------------------*/ 7 | #include "diskio.h" 8 | #include "ff.h" 9 | #include "rtc.h" 10 | #include "sd_card.h" 11 | 12 | #define BLOCK_SIZE 512 /* Block Size in Bytes */ 13 | 14 | DWORD get_fattime(void) 15 | { 16 | uint32_t year = 0; 17 | uint32_t mon = 0; 18 | uint32_t mday = 0; 19 | uint32_t hour = 0; 20 | uint32_t min = 0; 21 | uint32_t sec = 0; 22 | rtc_timer_get(&year, &mon, &mday, &hour, &min, &sec); 23 | return (year << 25) | (mon << 21) | (mday << 16) | (hour << 11) | (min << 5) | (sec / 2); 24 | } 25 | 26 | /*-----------------------------------------------------------------------*/ 27 | /* Read Sector(s) */ 28 | 29 | DRESULT disk_read(void *drv, BYTE *buff, DWORD sector, UINT count) 30 | { 31 | SD_ReadDisk(buff, sector, count); 32 | return RES_OK; 33 | } 34 | 35 | /*-----------------------------------------------------------------------*/ 36 | /* Write Sector(s) */ 37 | DRESULT disk_write(void *drv, const BYTE *buff, DWORD sector, UINT count) 38 | { 39 | SD_WriteDisk(buff, sector, count); 40 | return RES_OK; 41 | } 42 | 43 | /*-----------------------------------------------------------------------*/ 44 | /* Miscellaneous Functions */ 45 | 46 | DRESULT disk_ioctl(void *drv, BYTE cmd, void *buff) 47 | { 48 | 49 | *((DSTATUS *)buff) = 0; 50 | return RES_OK; 51 | } 52 | -------------------------------------------------------------------------------- /components/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | list(APPEND ADD_INCLUDE "base64/include" 4 | "cJSON/include" 5 | "image_op/include" 6 | "list/src" 7 | #option 8 | "jpeg_decode/include" 9 | "jpeg_encode/include" 10 | "cQueue/src" 11 | "qrcode/include" 12 | "qrcode/quirc/include" 13 | # "qrcode/zbar/include" 14 | #yuv_tab 15 | "yuv_tab/include" 16 | ) 17 | 18 | append_srcs_dir(ADD_SRCS "base64/src") 19 | append_srcs_dir(ADD_SRCS "cJSON/src") 20 | append_srcs_dir(ADD_SRCS "image_op/src") 21 | append_srcs_dir(ADD_SRCS "list/src") 22 | append_srcs_dir(ADD_SRCS "yuv_tab/src") 23 | 24 | if(CONFIG_ENABLE_JPEG_DECODE) 25 | append_srcs_dir(ADD_SRCS "jpeg_decode/src") 26 | endif() 27 | 28 | if(CONFIG_ENABLE_JPEG_ENCODE) 29 | append_srcs_dir(ADD_SRCS "jpeg_encode/src") 30 | endif() 31 | 32 | if(CONFIG_ENABLE_CQUEUE) 33 | append_srcs_dir(ADD_SRCS "cQueue/src") 34 | endif() 35 | 36 | if(CONFIG_ENABLE_QRCODE) 37 | append_srcs_dir(ADD_SRCS "qrcode/src") 38 | if(CONFIG_QRCODE_TYPE_QUIRC) 39 | append_srcs_dir(ADD_SRCS "qrcode/quirc/src") 40 | elseif(CONFIG_QRCODE_TYPE_ZBAR) 41 | append_srcs_dir(ADD_SRCS "qrcode/zbar/src") 42 | endif() 43 | endif() 44 | 45 | register_component() 46 | 47 | -------------------------------------------------------------------------------- /components/utils/Kconfig: -------------------------------------------------------------------------------- 1 | 2 | menu "utils config" 3 | 4 | menu "list config" 5 | config LIST_MAX_NUM 6 | int "list max num" 7 | default 1 8 | config LIST_NODE_MAX_NUM 9 | int "list node num" 10 | default 32 11 | config LIST_ITERATOR_MAX_NUM 12 | int "list iterator num" 13 | default 2 14 | endmenu 15 | 16 | config ENABLE_CQUEUE 17 | bool "enable cqueue module" 18 | default n 19 | 20 | config ENABLE_JPEG_DECODE 21 | bool "enable jpeg decode" 22 | default y 23 | 24 | config ENABLE_JPEG_ENCODE 25 | bool "enable jpeg encode" 26 | default y 27 | 28 | # sd_card 29 | osource "${SDK_PATH}/components/utils/qrcode/Kconfig" 30 | 31 | endmenu 32 | 33 | -------------------------------------------------------------------------------- /components/utils/base64/include/base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Base64 encoding/decoding (RFC1341) 3 | * Copyright (c) 2005, Jouni Malinen 4 | * 5 | * This software may be distributed under the terms of the BSD license. 6 | * See README for more details. 7 | */ 8 | 9 | #ifndef BASE64_H 10 | #define BASE64_H 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | unsigned char *base64_encode(const unsigned char *src, size_t len, size_t *out_len); 17 | unsigned char *base64_decode(const unsigned char *src, size_t len, size_t *out_len); 18 | 19 | #endif /* BASE64_H */ 20 | -------------------------------------------------------------------------------- /components/utils/image_op/include/ascii_font.h: -------------------------------------------------------------------------------- 1 | #ifndef __ASCII_FONT_H 2 | #define __ASCII_FONT_H 3 | 4 | #include 5 | 6 | extern const uint8_t ascii0816[]; 7 | extern const uint8_t ascii_1632[]; 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /components/utils/image_op/include/image_op.h: -------------------------------------------------------------------------------- 1 | #ifndef __IMAGE_OP_H 2 | #define __IMAGE_OP_H 3 | 4 | #include 5 | 6 | void image_rgb888_roate_right90(uint8_t *out, uint8_t *src, uint16_t w, 7 | uint16_t h); 8 | void image_rgb888_roate_left90(uint8_t *out, uint8_t *src, uint16_t w, 9 | uint16_t h); 10 | 11 | void convert_rgb565_order(uint16_t *image, uint16_t w, uint16_t h); 12 | 13 | void image_rgb565_roate_right90_lessmem(uint16_t *buf, uint16_t w, uint16_t h); 14 | void image_rgb565_roate_right90(uint16_t *out, uint16_t *src, uint16_t w, 15 | uint16_t h); 16 | void image_rgb565_roate_left90(uint16_t *out, uint16_t *src, uint16_t w, 17 | uint16_t h); 18 | 19 | void image_r8g8b8_roate_right90(uint8_t *out, uint8_t *src, uint16_t w, 20 | uint16_t h); 21 | void image_r8g8b8_roate_left90(uint8_t *out, uint8_t *src, uint16_t w, 22 | uint16_t h); 23 | 24 | void image_rgb5652rgb888(uint16_t *rgb565, uint8_t *rgb888, uint16_t img_w, 25 | uint16_t img_h); 26 | 27 | void image_rgb565_draw_edge(uint32_t *gram, 28 | uint16_t x1, uint16_t y1, 29 | uint16_t x2, uint16_t y2, 30 | uint16_t color, uint16_t img_w, uint16_t img_h); 31 | 32 | void image_rgb565_draw_string(uint16_t *ptr, char *str, uint8_t size, 33 | uint16_t x, uint16_t y, 34 | uint16_t color, uint16_t *bg_color, 35 | uint16_t img_w, uint16_t img_h); 36 | 37 | typedef uint8_t (*get_zhCN_dat)(uint8_t *zhCN_char, uint8_t *zhCN_dat, uint8_t size); 38 | 39 | void image_rgb565_draw_zhCN_string(uint16_t *ptr, uint8_t *zhCN_string, uint8_t size, 40 | uint16_t x, uint16_t y, 41 | uint16_t color, uint16_t *bg_color, 42 | uint16_t img_w, uint16_t img_h, 43 | get_zhCN_dat get_font_data); 44 | 45 | typedef struct 46 | { 47 | uint16_t *img_addr; 48 | uint16_t x; 49 | uint16_t y; 50 | uint16_t w; 51 | uint16_t h; 52 | } mix_image_t; 53 | 54 | void image_rgb565_mix_pic_with_alpha_lessmem(mix_image_t *img_src, mix_image_t *img_dst, 55 | uint32_t dst_addr, uint32_t alpha, uint8_t del_white, 56 | int (*flash_read_data)(uint32_t addr, uint8_t *data_buf, uint32_t length)); 57 | 58 | void image_rgb565_mix_pic_with_alpha(mix_image_t *img_src, mix_image_t *img_dst, uint32_t alpha, uint8_t del_white); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /components/utils/image_op/zhCN_FONT/GB2312/GB2312.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/components/utils/image_op/zhCN_FONT/GB2312/GB2312.txt -------------------------------------------------------------------------------- /components/utils/image_op/zhCN_FONT/GB2312/GB2312_16_32.kfpkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/components/utils/image_op/zhCN_FONT/GB2312/GB2312_16_32.kfpkg -------------------------------------------------------------------------------- /components/utils/image_op/zhCN_FONT/GB2312/GB2312_16x16.FON: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/components/utils/image_op/zhCN_FONT/GB2312/GB2312_16x16.FON -------------------------------------------------------------------------------- /components/utils/image_op/zhCN_FONT/GB2312/GB2312_32x32.FON: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/components/utils/image_op/zhCN_FONT/GB2312/GB2312_32x32.FON -------------------------------------------------------------------------------- /components/utils/image_op/zhCN_FONT/GBK/GBK12.FON: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/components/utils/image_op/zhCN_FONT/GBK/GBK12.FON -------------------------------------------------------------------------------- /components/utils/image_op/zhCN_FONT/GBK/GBK16.FON: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/components/utils/image_op/zhCN_FONT/GBK/GBK16.FON -------------------------------------------------------------------------------- /components/utils/image_op/zhCN_FONT/GBK/GBK24.FON: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/components/utils/image_op/zhCN_FONT/GBK/GBK24.FON -------------------------------------------------------------------------------- /components/utils/image_op/zhCN_FONT/GBK/GBK32.FON: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/components/utils/image_op/zhCN_FONT/GBK/GBK32.FON -------------------------------------------------------------------------------- /components/utils/image_op/zhCN_FONT/GBK/UNIGBK.BIN: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/components/utils/image_op/zhCN_FONT/GBK/UNIGBK.BIN -------------------------------------------------------------------------------- /components/utils/jpeg_decode/include/picojpeg_util.h: -------------------------------------------------------------------------------- 1 | #ifndef __PICOJPEG_UTIL_H__ 2 | #define __PICOJPEG_UTIL_H__ 3 | 4 | #include 5 | 6 | typedef struct _jpeg_decode_image 7 | { 8 | uint16_t width; 9 | uint16_t height; 10 | uint8_t comps; 11 | uint8_t scan_type; 12 | uint8_t *img_data; 13 | } jpeg_decode_image_t; 14 | 15 | void convert_jpeg_img_order(jpeg_decode_image_t *jpeg); 16 | jpeg_decode_image_t *pico_jpeg_decode(uint8_t *out_img, uint8_t *buf, uint32_t buf_len, uint8_t rgb565); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /components/utils/list/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | bin 3 | .pomo 4 | *.o 5 | build 6 | deps 7 | -------------------------------------------------------------------------------- /components/utils/list/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | before_install: 3 | - sudo apt-get update 4 | - sudo apt-get install libcurl4-gnutls-dev valgrind -qq 5 | - git clone https://github.com/clibs/clib.git /tmp/clib 6 | - sudo make -C /tmp/clib install 7 | install: clib install --dev 8 | script: 9 | - make bin/test 10 | - valgrind --leak-check=full --error-exitcode=5 ./bin/test 11 | -------------------------------------------------------------------------------- /components/utils/list/History.md: -------------------------------------------------------------------------------- 1 | 2 | 0.0.8 / 2015-01-30 3 | ================== 4 | 5 | * fix `list_at` unsigned compare error (bolasblack, #13) 6 | * travis: Fail the build if any memory is leaked 7 | * travis: Update before installing deps 8 | * test: Fix memory leaks 9 | 10 | 0.0.7 / 2014-06-02 11 | ================== 12 | 13 | * ci: Remove benchmarks 14 | * add travis 15 | * test: Fix 'unused parameter' warning 16 | * readme: Update benchmarks 17 | * benchmark: Fix 'unused parameter' warning 18 | * benchmark: Use clibs/bench for CPU time 19 | * readme: Correct types 20 | * readme: Add syntax highlighting 21 | * iterator: set to `NULL` after freeing 22 | 23 | 0.0.6 / 2014-05-06 24 | ================== 25 | 26 | * list.h: Fix header guards 27 | * Add “list” prefix to sources 28 | 29 | 0.0.5 / 2013-10-20 30 | ================== 31 | 32 | * add package.json 33 | * fix free in link_remove(). Closes #3 34 | 35 | 0.0.4 / 2011-04-15 36 | ================== 37 | 38 | * pop -> rpop 39 | * shift -> lpop 40 | * push -> rpush 41 | * unshift -> lpush 42 | 43 | 0.0.3 / 2010-11-27 44 | ================== 45 | 46 | * Added `make install` 47 | * Added `list_shift()` 48 | * Added `list_pop()` 49 | * Lowercased function names and typedefs 50 | * Wrap with extern "C" when \_\_cplusplus 51 | * Installing `list.h` 52 | 53 | 0.0.2 / 2010-08-21 54 | ================== 55 | 56 | * Added `ListNode *List_at(List *self, int index)` 57 | * Added `void List_remove(List *self, ListNode *node)` 58 | * Added `make liblist.a` 59 | 60 | 0.0.1 / 2010-08-13 61 | ================== 62 | 63 | * Initial release 64 | -------------------------------------------------------------------------------- /components/utils/list/Makefile: -------------------------------------------------------------------------------- 1 | 2 | AR ?= ar 3 | CC ?= gcc 4 | PREFIX ?= /usr/local 5 | 6 | CFLAGS = -O3 -std=c99 -Wall -Wextra -Ideps 7 | 8 | SRCS = src/list.c \ 9 | src/list_node.c \ 10 | src/list_iterator.c 11 | 12 | OBJS = $(SRCS:.c=.o) 13 | 14 | all: build/liblist.a 15 | 16 | install: all 17 | cp -f build/liblist.a $(PREFIX)/lib/liblist.a 18 | cp -f src/list.h $(PREFIX)/include/list.h 19 | 20 | uninstall: 21 | rm -f $(PREFIX)/lib/liblist.a 22 | rm -f $(PREFIX)/include/list.h 23 | 24 | build/liblist.a: $(OBJS) 25 | @mkdir -p build 26 | $(AR) rcs $@ $^ 27 | 28 | bin/test: test.o $(OBJS) 29 | @mkdir -p bin 30 | $(CC) $^ -o $@ 31 | 32 | bin/benchmark: benchmark.o $(OBJS) 33 | @mkdir -p bin 34 | $(CC) $^ -o $@ 35 | 36 | %.o: %.c 37 | $(CC) $< $(CFLAGS) -c -o $@ 38 | 39 | clean: 40 | rm -fr bin build *.o src/*.o 41 | 42 | test: bin/test 43 | @./$< 44 | 45 | benchmark: bin/benchmark 46 | @./$< 47 | 48 | .PHONY: test benchmark clean install uninstall 49 | -------------------------------------------------------------------------------- /components/utils/list/benchmark.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "bench/bench.h" 4 | #include "src/list.h" 5 | 6 | static void 7 | bm(char *label, void (*fn)()) { 8 | printf(" %18s", label); 9 | fflush(stdout); 10 | fn(); 11 | } 12 | 13 | static int nnodes = 10000000; 14 | static float startTime; 15 | 16 | 17 | static void 18 | start() { 19 | startTime = cpu(); 20 | } 21 | 22 | static void 23 | stop() { 24 | float duration = cpu() - startTime; 25 | printf(": \x1b[32m%.4f\x1b[0ms\n", duration); 26 | } 27 | 28 | static void 29 | bm_rpush() { 30 | start(); 31 | int n = nnodes; 32 | list_t *list = list_new(); 33 | while (n--) { 34 | list_rpush(list, list_node_new("foo")); 35 | } 36 | stop(); 37 | } 38 | 39 | static void 40 | bm_lpush() { 41 | start(); 42 | int n = nnodes; 43 | list_t *list = list_new(); 44 | while (n--) { 45 | list_lpush(list, list_node_new("foo")); 46 | } 47 | stop(); 48 | } 49 | 50 | static void 51 | bm_find() { 52 | int n = nnodes; 53 | list_t *list = list_new(); 54 | while (n--) { 55 | list_lpush(list, list_node_new("foo")); 56 | } 57 | list_rpush(list, list_node_new("bar")); 58 | start(); 59 | list_find(list, "bar"); 60 | stop(); 61 | } 62 | 63 | static void 64 | bm_iterate() { 65 | int n = nnodes; 66 | list_t *list = list_new(); 67 | while (n--) { 68 | list_lpush(list, list_node_new("foo")); 69 | } 70 | list_iterator_t *it = list_iterator_new(list, LIST_HEAD); 71 | list_node_t *node; 72 | start(); 73 | while ((node = list_iterator_next(it))) 74 | ; 75 | stop(); 76 | } 77 | 78 | static void 79 | bm_rpop() { 80 | int n = nnodes; 81 | list_t *list = list_new(); 82 | while (n--) { 83 | list_lpush(list, list_node_new("foo")); 84 | } 85 | list_node_t *node; 86 | start(); 87 | while ((node = list_rpop(list))) 88 | ; 89 | stop(); 90 | } 91 | 92 | static void 93 | bm_lpop() { 94 | int n = nnodes; 95 | list_t *list = list_new(); 96 | while (n--) { 97 | list_lpush(list, list_node_new("foo")); 98 | } 99 | list_node_t *node; 100 | start(); 101 | while ((node = list_lpop(list))) 102 | ; 103 | stop(); 104 | } 105 | 106 | static list_t *list; 107 | 108 | static void 109 | bm_at() { 110 | start(); 111 | list_at(list, 100000); 112 | stop(); 113 | } 114 | 115 | static void 116 | bm_at2() { 117 | start(); 118 | list_at(list, 1000000); 119 | stop(); 120 | } 121 | 122 | static void 123 | bm_at3() { 124 | start(); 125 | list_at(list, -100000); 126 | stop(); 127 | } 128 | 129 | int 130 | main(void){ 131 | int n = nnodes; 132 | list = list_new(); 133 | while (n--) list_lpush(list, list_node_new("foo")); 134 | puts("\n 10,000,000 nodes\n"); 135 | bm("lpush", bm_lpush); 136 | bm("rpush", bm_rpush); 137 | bm("lpop", bm_lpop); 138 | bm("rpop", bm_rpop); 139 | bm("find (last node)", bm_find); 140 | bm("iterate", bm_iterate); 141 | bm("at(100,000)", bm_at); 142 | bm("at(1,000,000)", bm_at2); 143 | bm("at(-100,000)", bm_at3); 144 | puts(""); 145 | return 0; 146 | } 147 | -------------------------------------------------------------------------------- /components/utils/list/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "list", 3 | "version": "0.0.8", 4 | "repo": "clibs/list", 5 | "description": "Simple linked list", 6 | "keywords": ["list", "structure"], 7 | "license": "MIT", 8 | "src": [ 9 | "src/list_iterator.c", 10 | "src/list.c", 11 | "src/list_node.c", 12 | "src/list.h" 13 | ], 14 | "development": { 15 | "bench": "*" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /components/utils/list/src/list.h: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // list.h 4 | // 5 | // Copyright (c) 2010 TJ Holowaychuk 6 | // 7 | 8 | #ifndef LIST_H 9 | #define LIST_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include 16 | 17 | // Library version 18 | 19 | #define LIST_VERSION "0.0.5" 20 | 21 | // Memory management macros 22 | 23 | /* 24 | #ifndef LIST_MALLOC 25 | #define LIST_MALLOC malloc 26 | #endif 27 | 28 | #ifndef LIST_FREE 29 | #define LIST_FREE free 30 | #endif 31 | 32 | */ 33 | 34 | /* 35 | * list_t iterator direction. 36 | */ 37 | 38 | typedef enum { 39 | LIST_HEAD 40 | , LIST_TAIL 41 | } list_direction_t; 42 | 43 | /* 44 | * list_t node struct. 45 | */ 46 | 47 | typedef struct list_node { 48 | struct list_node *prev; 49 | struct list_node *next; 50 | void *val; 51 | } list_node_t; 52 | 53 | /* 54 | * list_t struct. 55 | */ 56 | 57 | typedef struct { 58 | list_node_t *head; 59 | list_node_t *tail; 60 | unsigned int len; 61 | void (*free)(void *val); 62 | int (*match)(void *a, void *b); 63 | } list_t; 64 | 65 | /* 66 | * list_t iterator struct. 67 | */ 68 | 69 | typedef struct { 70 | list_node_t *next; 71 | list_direction_t direction; 72 | } list_iterator_t; 73 | 74 | // Node prototypes. 75 | 76 | list_node_t * 77 | list_node_new(void *val); 78 | 79 | // list_t prototypes. 80 | 81 | list_t * 82 | list_new(); 83 | 84 | list_node_t * 85 | list_rpush(list_t *self, list_node_t *node); 86 | 87 | list_node_t * 88 | list_lpush(list_t *self, list_node_t *node); 89 | 90 | list_node_t * 91 | list_find(list_t *self, void *val); 92 | 93 | list_node_t * 94 | list_at(list_t *self, int index); 95 | 96 | list_node_t * 97 | list_rpop(list_t *self); 98 | 99 | list_node_t * 100 | list_lpop(list_t *self); 101 | 102 | void 103 | list_remove(list_t *self, list_node_t *node); 104 | 105 | void 106 | list_destroy(list_t *self); 107 | 108 | // list_t iterator prototypes. 109 | 110 | list_iterator_t * 111 | list_iterator_new(list_t *list, list_direction_t direction); 112 | 113 | list_iterator_t * 114 | list_iterator_new_from_node(list_node_t *node, list_direction_t direction); 115 | 116 | list_node_t * 117 | list_iterator_next(list_iterator_t *self); 118 | 119 | void 120 | list_iterator_destroy(list_iterator_t *self); 121 | 122 | 123 | void list_static_init(void); 124 | 125 | list_t *malloc_list(void); 126 | void free_list(list_node_t *list); 127 | 128 | list_node_t *malloc_list_node(void); 129 | void free_list_node(list_node_t *node); 130 | void free_all_node(void); 131 | 132 | list_iterator_t *malloc_list_iterator(void); 133 | void free_list_iterator(list_iterator_t *it); 134 | 135 | #ifdef __cplusplus 136 | } 137 | #endif 138 | 139 | #endif /* LIST_H */ 140 | -------------------------------------------------------------------------------- /components/utils/list/src/list_iterator.c: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // iterator.c 4 | // 5 | // Copyright (c) 2010 TJ Holowaychuk 6 | // 7 | 8 | #include "list.h" 9 | 10 | /* 11 | * Allocate a new list_iterator_t. NULL on failure. 12 | * Accepts a direction, which may be LIST_HEAD or LIST_TAIL. 13 | */ 14 | 15 | list_iterator_t * 16 | list_iterator_new(list_t *list, list_direction_t direction) { 17 | list_node_t *node = direction == LIST_HEAD 18 | ? list->head 19 | : list->tail; 20 | return list_iterator_new_from_node(node, direction); 21 | } 22 | 23 | /* 24 | * Allocate a new list_iterator_t with the given start 25 | * node. NULL on failure. 26 | */ 27 | 28 | list_iterator_t * 29 | list_iterator_new_from_node(list_node_t *node, list_direction_t direction) { 30 | list_iterator_t *self; 31 | // if (!(self = LIST_MALLOC(sizeof(list_iterator_t)))) 32 | if (!(self = malloc_list_iterator())) 33 | return NULL; 34 | self->next = node; 35 | self->direction = direction; 36 | return self; 37 | } 38 | 39 | /* 40 | * Return the next list_node_t or NULL when no more 41 | * nodes remain in the list. 42 | */ 43 | 44 | list_node_t * 45 | list_iterator_next(list_iterator_t *self) { 46 | list_node_t *curr = self->next; 47 | if (curr) { 48 | self->next = self->direction == LIST_HEAD 49 | ? curr->next 50 | : curr->prev; 51 | } 52 | return curr; 53 | } 54 | 55 | /* 56 | * Free the list iterator. 57 | */ 58 | 59 | void 60 | list_iterator_destroy(list_iterator_t *self) { 61 | // LIST_FREE(self); 62 | free_list_iterator(self); 63 | self = NULL; 64 | } 65 | -------------------------------------------------------------------------------- /components/utils/list/src/list_node.c: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // node.c 4 | // 5 | // Copyright (c) 2010 TJ Holowaychuk 6 | // 7 | 8 | #include "list.h" 9 | 10 | /* 11 | * Allocates a new list_node_t. NULL on failure. 12 | */ 13 | 14 | list_node_t * 15 | list_node_new(void *val) { 16 | list_node_t *self; 17 | // if (!(self = LIST_MALLOC(sizeof(list_node_t)))) 18 | if (!(self = malloc_list_node())) 19 | return NULL; 20 | self->prev = NULL; 21 | self->next = NULL; 22 | self->val = val; 23 | return self; 24 | } -------------------------------------------------------------------------------- /components/utils/qrcode/Kconfig: -------------------------------------------------------------------------------- 1 | menuconfig ENABLE_QRCODE 2 | bool "enable qrcode scan" 3 | default y 4 | 5 | choice QRCODE_TYPE 6 | depends on ENABLE_QRCODE 7 | 8 | bool "Qrcode engine" 9 | default QRCODE_TYPE_QUIRC 10 | 11 | config QRCODE_TYPE_QUIRC 12 | bool "Qrcode decode use Quirc" 13 | config QRCODE_TYPE_ZBAR 14 | bool "Qrcode decode use Zbar" 15 | endchoice -------------------------------------------------------------------------------- /components/utils/qrcode/include/maix_qrcode.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAIX_QRCODE_H 2 | #define __MAIX_QRCODE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "yuv_tab.h" 12 | /////////////////////////////////////////////////////////////////////////////// 13 | #define QUIRC_MAX_PAYLOAD 255 14 | 15 | #define SWAP_16(x) ((x >> 8 & 0xff) | (x << 8)) 16 | 17 | #define COLOR_RGB565_TO_Y(pixel) yuv_table((pixel)*3) 18 | 19 | #define COLOR_RGB565_TO_GRAYSCALE(pixel) (COLOR_RGB565_TO_Y(pixel) + 128) 20 | 21 | #define IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x) \ 22 | ({ \ 23 | __typeof__(row_ptr) _row_ptr = (row_ptr); \ 24 | __typeof__(x) _x = (x); \ 25 | _row_ptr[_x]; \ 26 | }) 27 | 28 | #define IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(image, y) \ 29 | ({ \ 30 | __typeof__(image) _image = (image); \ 31 | __typeof__(y) _y = (y); \ 32 | ((uint16_t *)_image->data) + (_image->w * _y); \ 33 | }) 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | enum enum_qrcode_res 37 | { 38 | QRCODE_SUCC = 0, /* 0: 扫码成功 */ 39 | QRCODE_NONE = 1, /* 1: 扫码失败 */ 40 | QRCODE_ERROR = 2, /* 出错 */ 41 | QRCODE_TIMEOUT = 3, /* 2: 扫码超时 */ 42 | }; 43 | 44 | typedef struct _qrcode_image 45 | { 46 | int w; 47 | int h; 48 | int bpp; 49 | union { 50 | uint8_t *pixels; 51 | uint8_t *data; 52 | }; 53 | } qrcode_image_t; 54 | 55 | typedef struct _qrcode_scan 56 | { 57 | int scan_time_out_s; 58 | uint64_t start_time_us; 59 | 60 | uint16_t img_w; 61 | uint16_t img_h; 62 | uint8_t *img_data; 63 | 64 | /* http://chicore.cn/doc/1180830026001202.htm */ 65 | uint8_t qrcode_num; 66 | 67 | uint8_t qrcode[QUIRC_MAX_PAYLOAD]; 68 | } qrcode_scan_t; 69 | 70 | /////////////////////////////////////////////////////////////////////////////// 71 | /* SDK中的函数 */ 72 | extern int printk(const char *format, ...); 73 | extern uint64_t sysctl_get_time_us(void); 74 | /* 工程中函数 */ 75 | extern void set_W_LED(int state); 76 | 77 | void qrcode_convert_order(qrcode_image_t *img); 78 | void qrcode_convert_to_gray(qrcode_image_t *img, uint8_t *gray); 79 | 80 | enum enum_qrcode_res qrcode_scan(qrcode_scan_t *scan, uint8_t convert); 81 | 82 | #endif /* __QRCODE_H */ 83 | -------------------------------------------------------------------------------- /components/utils/qrcode/quirc/include/quirc.h: -------------------------------------------------------------------------------- 1 | #ifndef __QUIRC_H 2 | #define __QUIRC_H 3 | 4 | #include 5 | #include 6 | 7 | #include "maix_qrcode.h" 8 | 9 | typedef struct qrcode_res 10 | { 11 | /* Various parameters of the QR-code. These can mostly be 12 | * ignored if you only care about the data. 13 | */ 14 | int version; 15 | int ecc_level; 16 | int mask; 17 | 18 | /* This field is the highest-valued data type found in the QR 19 | * code. 20 | */ 21 | int data_type; 22 | 23 | /* Data payload. For the Kanji datatype, payload is encoded as 24 | * Shift-JIS. For all other datatypes, payload is ASCII text. 25 | */ 26 | uint8_t payload[QUIRC_MAX_PAYLOAD]; 27 | int payload_len; 28 | 29 | /* ECI assignment number */ 30 | uint32_t eci; 31 | } qrcode_result_t __attribute__((aligned(8))); 32 | 33 | uint8_t find_qrcodes(qrcode_result_t *out, qrcode_image_t *img, qrcode_scan_t *scan, uint8_t convert); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /components/utils/qrcode/src/maix_qrcode.c: -------------------------------------------------------------------------------- 1 | #include "maix_qrcode.h" 2 | 3 | #include "global_config.h" 4 | 5 | #if CONFIG_QRCODE_TYPE_QUIRC 6 | #include "quirc.h" 7 | #endif /* CONFIG_QRCODE_TYPE_QUIRC */ 8 | 9 | #if CONFIG_QRCODE_TYPE_ZBAR 10 | // #include "zbar.h" 11 | #endif /* CONFIG_QRCODE_TYPE_ZBAR */ 12 | 13 | /////////////////////////////////////////////////////////////////////////////// 14 | void qrcode_convert_order(qrcode_image_t *img) 15 | { 16 | uint16_t t[2], *ptr = (uint16_t *)(img->data); 17 | 18 | for (uint32_t i = 0; i < (img->w * img->h); i += 2) 19 | { 20 | t[0] = *(ptr + 1); 21 | t[1] = *(ptr); 22 | *(ptr) = SWAP_16(t[0]); 23 | *(ptr + 1) = SWAP_16(t[1]); 24 | ptr += 2; 25 | } 26 | return; 27 | } 28 | 29 | void qrcode_convert_to_gray(qrcode_image_t *img, uint8_t *gray) 30 | { 31 | for (int y = 0, yy = img->h; y < yy; y++) 32 | { 33 | uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(img, y); 34 | for (int x = 0, xx = img->w; x < xx; x++) 35 | { 36 | *(gray++) = IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, img->w - x) & 0xff; 37 | // *(grayscale_image++) = COLOR_RGB565_TO_GRAYSCALE(IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, img->w - x)); 38 | } 39 | } 40 | return; 41 | } 42 | /////////////////////////////////////////////////////////////////////////////// 43 | /* 0: 扫码成功 44 | 1: 扫码失败 45 | 2: 扫码超时 46 | 3: 二维码内容太大 47 | 4: 未知异常 48 | */ 49 | enum enum_qrcode_res qrcode_scan(qrcode_scan_t *scan, uint8_t convert) 50 | { 51 | enum enum_qrcode_res ret; 52 | qrcode_image_t img; 53 | 54 | #if !CONFIG_ALWAYS_SCAN_QRCODES 55 | if ((sysctl_get_time_us() - (scan->start_time_us)) > (scan->scan_time_out_s * 1000 * 1000)) 56 | { 57 | return QRCODE_TIMEOUT; 58 | } 59 | #endif /* CONFIG_ALWAYS_SCAN_QRCODES */ 60 | 61 | if (scan->img_data == NULL) 62 | { 63 | return QRCODE_ERROR; 64 | } 65 | 66 | memset(&img, 0, sizeof(img)); 67 | img.w = scan->img_w; /* 320 */ 68 | img.h = scan->img_h; /* 240 */ 69 | img.data = (uint8_t *)(scan->img_data); 70 | 71 | scan->qrcode_num = 0; 72 | 73 | #if CONFIG_QRCODE_TYPE_QUIRC 74 | qrcode_result_t qrcode; 75 | if (find_qrcodes(&qrcode, &img, scan, convert) != 0) 76 | { 77 | // if (/* qrcode.version <= 6 && */ qrcode.payload_len >= QUIRC_MAX_PAYLOAD) 78 | // { 79 | // printk("qrcode content too big than buffer\r\n"); 80 | // return QRCODE_TOOBIG; 81 | // } 82 | // else 83 | { 84 | memcpy(scan->qrcode, qrcode.payload, qrcode.payload_len); 85 | scan->qrcode[qrcode.payload_len] = 0; 86 | ret = QRCODE_SUCC; 87 | } 88 | } 89 | #elif CONFIG_QRCODE_TYPE_ZBAR 90 | extern uint8_t find_qrcodes(qrcode_image_t * img, qrcode_scan_t * scan, uint8_t convert); 91 | if (find_qrcodes(&img, scan, convert) != 0) 92 | { 93 | ret = QRCODE_SUCC; 94 | } 95 | #else 96 | #error "Must choose one qrcode engine" 97 | #endif 98 | else 99 | { 100 | ret = QRCODE_NONE; 101 | } 102 | 103 | #if CONFIG_ALWAYS_SCAN_QRCODES 104 | /* 有二维码就开led,没有就关闭 */ 105 | set_W_LED(scan->qrcode_num ? 1 : 0); 106 | #endif 107 | 108 | return ret; 109 | } 110 | -------------------------------------------------------------------------------- /components/utils/qrcode/zbar/src/bch15_5.h: -------------------------------------------------------------------------------- 1 | /*Copyright (C) 2008-2009 Timothy B. Terriberry (tterribe@xiph.org) 2 | You can redistribute this library and/or modify it under the terms of the 3 | GNU Lesser General Public License as published by the Free Software 4 | Foundation; either version 2.1 of the License, or (at your option) any later 5 | version.*/ 6 | #if !defined(_bch15_5_H) 7 | # define _bch15_5_H (1) 8 | 9 | /*Encodes a raw 5-bit value _x into a 15-bit BCH(15,5) code. 10 | This is capable of correcting up to 3 bit errors, and detecting as many as 11 | 5 bit errors in some cases.*/ 12 | unsigned bch15_5_encode(unsigned _x); 13 | 14 | /*Corrects the received code *_y, if possible. 15 | The original data is located in the top five bits. 16 | Returns the number of errors corrected, or a negative value if decoding 17 | failed due to too many bit errors, in which case *_y is left unchanged.*/ 18 | int bch15_5_correct(unsigned *_y); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /components/utils/qrcode/zbar/src/binarize.h: -------------------------------------------------------------------------------- 1 | /*Copyright (C) 2008-2009 Timothy B. Terriberry (tterribe@xiph.org) 2 | You can redistribute this library and/or modify it under the terms of the 3 | GNU Lesser General Public License as published by the Free Software 4 | Foundation; either version 2.1 of the License, or (at your option) any later 5 | version.*/ 6 | #if !defined(_qrcode_binarize_H) 7 | # define _qrcode_binarize_H (1) 8 | 9 | void qr_image_cross_masking_median_filter(unsigned char *_img, 10 | int _width,int _height); 11 | 12 | void qr_wiener_filter(unsigned char *_img,int _width,int _height); 13 | 14 | /*Binarizes a grayscale image.*/ 15 | unsigned char *qr_binarize(const unsigned char *_img,int _width,int _height); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /components/utils/qrcode/zbar/src/debug.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------ 2 | * Copyright 2007-2009 (c) Jeff Brown 3 | * 4 | * This file is part of the ZBar Bar Code Reader. 5 | * 6 | * The ZBar Bar Code Reader is free software; you can redistribute it 7 | * and/or modify it under the terms of the GNU Lesser Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * The ZBar Bar Code Reader is distributed in the hope that it will be 12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser Public License 17 | * along with the ZBar Bar Code Reader; if not, write to the Free 18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * 21 | * http://sourceforge.net/projects/zbar 22 | *------------------------------------------------------------------------*/ 23 | 24 | /* varargs variations on compile time debug spew */ 25 | 26 | #ifndef DEBUG_LEVEL 27 | 28 | #ifdef __GNUC__ 29 | /* older versions of gcc (< 2.95) require a named varargs parameter */ 30 | #define dprintf(args...) 31 | #else 32 | /* unfortunately named vararg parameter is a gcc-specific extension */ 33 | #define dprintf(...) 34 | #endif 35 | 36 | #else 37 | 38 | #include 39 | 40 | #ifdef __GNUC__ 41 | #define dprintf(level, args...) \ 42 | if ((level) <= DEBUG_LEVEL) \ 43 | fprintf(stderr, args) 44 | #else 45 | #define dprintf(level, ...) \ 46 | if ((level) <= DEBUG_LEVEL) \ 47 | fprintf(stderr, __VA_ARGS__) 48 | #endif 49 | 50 | #endif /* DEBUG_LEVEL */ 51 | 52 | /* spew warnings for non-fatal assertions. 53 | * returns specified error code if assertion fails. 54 | * NB check/return is still performed for NDEBUG 55 | * only the message is inhibited 56 | * FIXME don't we need varargs hacks here? 57 | */ 58 | #ifndef NDEBUG 59 | 60 | #include 61 | 62 | #if __STDC_VERSION__ < 199901L && !defined(__func__) 63 | #if __GNUC__ >= 2 64 | #define __func__ __FUNCTION__ 65 | #else 66 | #define __func__ "" 67 | #endif 68 | #endif 69 | 70 | /* 71 | #define zassert(condition, retval, format, ...) \ 72 | do \ 73 | { \ 74 | if (!(condition)) \ 75 | { \ 76 | fprintf(stderr, "WARNING: %s:%d: %s:" \ 77 | " Assertion \"%s\" failed.\n\t" format, \ 78 | __FILE__, __LINE__, __func__, #condition, \ 79 | ##__VA_ARGS__); \ 80 | return (retval); \ 81 | } \ 82 | } while (0) 83 | */ 84 | 85 | # define zassert(condition, retval, format, ...) 86 | #else 87 | 88 | #define zassert(condition, retval, format, ...) \ 89 | do \ 90 | { \ 91 | if (!(condition)) \ 92 | return (retval); \ 93 | } while (0) 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /components/utils/qrcode/zbar/src/img_scanner.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------ 2 | * Copyright 2007-2009 (c) Jeff Brown 3 | * 4 | * This file is part of the ZBar Bar Code Reader. 5 | * 6 | * The ZBar Bar Code Reader is free software; you can redistribute it 7 | * and/or modify it under the terms of the GNU Lesser Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * The ZBar Bar Code Reader is distributed in the hope that it will be 12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser Public License 17 | * along with the ZBar Bar Code Reader; if not, write to the Free 18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * 21 | * http://sourceforge.net/projects/zbar 22 | *------------------------------------------------------------------------*/ 23 | #ifndef _IMG_SCANNER_H_ 24 | #define _IMG_SCANNER_H_ 25 | 26 | #include "zbar.h" 27 | 28 | /* internal image scanner APIs for 2D readers */ 29 | 30 | extern zbar_symbol_t *_zbar_image_scanner_alloc_sym(zbar_image_scanner_t*, 31 | zbar_symbol_type_t, 32 | int); 33 | extern void _zbar_image_scanner_add_sym(zbar_image_scanner_t*, 34 | zbar_symbol_t*); 35 | extern void _zbar_image_scanner_recycle_syms(zbar_image_scanner_t*, 36 | zbar_symbol_t*); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /components/utils/qrcode/zbar/src/isaac.h: -------------------------------------------------------------------------------- 1 | /*Written by Timothy B. Terriberry (tterribe@xiph.org) 1999-2009 public domain. 2 | Based on the public domain implementation by Robert J. Jenkins Jr.*/ 3 | #if !defined(_isaac_H) 4 | # define _isaac_H (1) 5 | 6 | 7 | 8 | typedef struct isaac_ctx isaac_ctx; 9 | 10 | 11 | 12 | #define ISAAC_SZ_LOG (8) 13 | #define ISAAC_SZ (1< 3 | 4 | #include "zbar.h" 5 | #include "decoder.h" 6 | 7 | #ifdef DEBUG_QR_FINDER 8 | # define DEBUG_LEVEL (DEBUG_QR_FINDER) 9 | #endif 10 | #include "debug.h" 11 | 12 | /* at this point lengths are all decode unit offsets from the decode edge 13 | * NB owned by finder 14 | */ 15 | qr_finder_line *_zbar_decoder_get_qr_finder_line (zbar_decoder_t *dcode) 16 | { 17 | return(&dcode->qrf.line); 18 | } 19 | 20 | zbar_symbol_type_t _zbar_find_qr (zbar_decoder_t *dcode) 21 | { 22 | qr_finder_t *qrf = &dcode->qrf; 23 | 24 | /* update latest finder pattern width */ 25 | qrf->s5 -= get_width(dcode, 6); 26 | qrf->s5 += get_width(dcode, 1); 27 | unsigned s = qrf->s5; 28 | 29 | if(get_color(dcode) != ZBAR_SPACE || s < 7) 30 | return(0); 31 | 32 | dprintf(2, " qrf: s=%d", s); 33 | 34 | int ei = decode_e(pair_width(dcode, 1), s, 7); 35 | dprintf(2, " %d", ei); 36 | if(ei) 37 | goto invalid; 38 | 39 | ei = decode_e(pair_width(dcode, 2), s, 7); 40 | dprintf(2, "%d", ei); 41 | if(ei != 2) 42 | goto invalid; 43 | 44 | ei = decode_e(pair_width(dcode, 3), s, 7); 45 | dprintf(2, "%d", ei); 46 | if(ei != 2) 47 | goto invalid; 48 | 49 | ei = decode_e(pair_width(dcode, 4), s, 7); 50 | dprintf(2, "%d", ei); 51 | if(ei) 52 | goto invalid; 53 | 54 | /* valid QR finder symbol 55 | * mark positions needed by decoder 56 | */ 57 | unsigned qz = get_width(dcode, 0); 58 | unsigned w = get_width(dcode, 1); 59 | qrf->line.eoffs = qz + (w + 1) / 2; 60 | qrf->line.len = qz + w + get_width(dcode, 2); 61 | qrf->line.pos[0] = qrf->line.len + get_width(dcode, 3); 62 | qrf->line.pos[1] = qrf->line.pos[0]; 63 | w = get_width(dcode, 5); 64 | qrf->line.boffs = qrf->line.pos[0] + get_width(dcode, 4) + (w + 1) / 2; 65 | 66 | dprintf(2, " boff=%d pos=%d len=%d eoff=%d [valid]\n", 67 | qrf->line.boffs, qrf->line.pos[0], qrf->line.len, 68 | qrf->line.eoffs); 69 | 70 | return(ZBAR_QRCODE); 71 | 72 | invalid: 73 | dprintf(2, " [invalid]\n"); 74 | return(0); 75 | } 76 | -------------------------------------------------------------------------------- /components/utils/qrcode/zbar/src/qr_finder.h: -------------------------------------------------------------------------------- 1 | #ifndef _DECODER_QR_FINDER_H_ 2 | #define _DECODER_QR_FINDER_H_ 3 | 4 | #include "qrcode.h" 5 | 6 | typedef struct qr_reader qr_reader; 7 | 8 | /* QR Code symbol finder state */ 9 | typedef struct qr_finder_s { 10 | unsigned s5; /* finder pattern width */ 11 | qr_finder_line line; /* position info needed by decoder */ 12 | 13 | unsigned config; 14 | } qr_finder_t; 15 | 16 | 17 | 18 | /* reset QR finder specific state */ 19 | static inline void qr_finder_reset (qr_finder_t *qrf) 20 | { 21 | qrf->s5 = 0; 22 | } 23 | 24 | /* find QR Code symbols */ 25 | zbar_symbol_type_t _zbar_find_qr (zbar_decoder_t *dcode); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /components/utils/qrcode/zbar/src/qrcode.h: -------------------------------------------------------------------------------- 1 | /*Copyright (C) 2008-2009 Timothy B. Terriberry (tterribe@xiph.org) 2 | You can redistribute this library and/or modify it under the terms of the 3 | GNU Lesser General Public License as published by the Free Software 4 | Foundation; either version 2.1 of the License, or (at your option) any later 5 | version.*/ 6 | #ifndef _QRCODE_H_ 7 | #define _QRCODE_H_ 8 | 9 | #include "zbar.h" 10 | 11 | typedef struct qr_reader qr_reader; 12 | 13 | typedef int qr_point[2]; 14 | typedef struct qr_finder_line qr_finder_line; 15 | 16 | /*The number of bits of subpel precision to store image coordinates in. 17 | This helps when estimating positions in low-resolution images, which may have 18 | a module pitch only a pixel or two wide, making rounding errors matter a 19 | great deal.*/ 20 | #define QR_FINDER_SUBPREC (2) 21 | 22 | /*A line crossing a finder pattern. 23 | Whether the line is horizontal or vertical is determined by context. 24 | The offsts to various parts of the finder pattern are as follows: 25 | |*****| |*****|*****|*****| |*****| 26 | |*****| |*****|*****|*****| |*****| 27 | ^ ^ ^ ^ 28 | | | | | 29 | | | | pos[v]+len+eoffs 30 | | | pos[v]+len 31 | | pos[v] 32 | pos[v]-boffs 33 | Here v is 0 for horizontal and 1 for vertical lines.*/ 34 | struct qr_finder_line { 35 | /*The location of the upper/left endpoint of the line. 36 | The left/upper edge of the center section is used, since other lines must 37 | cross in this region.*/ 38 | qr_point pos; 39 | /*The length of the center section. 40 | This extends to the right/bottom of the center section, since other lines 41 | must cross in this region.*/ 42 | int len; 43 | /*The offset to the midpoint of the upper/left section (part of the outside 44 | ring), or 0 if we couldn't identify the edge of the beginning section. 45 | We use the midpoint instead of the edge because it can be located more 46 | reliably.*/ 47 | int boffs; 48 | /*The offset to the midpoint of the end section (part of the outside ring), 49 | or 0 if we couldn't identify the edge of the end section. 50 | We use the midpoint instead of the edge because it can be located more 51 | reliably.*/ 52 | int eoffs; 53 | }; 54 | 55 | qr_reader *_zbar_qr_create(void); 56 | void _zbar_qr_destroy(qr_reader *reader); 57 | void _zbar_qr_reset(qr_reader *reader); 58 | 59 | int _zbar_qr_found_line(qr_reader *reader, 60 | int direction, 61 | const qr_finder_line *line); 62 | int _zbar_qr_decode(qr_reader *reader, 63 | zbar_image_scanner_t *iscn, 64 | zbar_image_t *img); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /components/utils/qrcode/zbar/src/refcnt.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------ 2 | * Copyright 2007-2009 (c) Jeff Brown 3 | * 4 | * This file is part of the ZBar Bar Code Reader. 5 | * 6 | * The ZBar Bar Code Reader is free software; you can redistribute it 7 | * and/or modify it under the terms of the GNU Lesser Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * The ZBar Bar Code Reader is distributed in the hope that it will be 12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser Public License 17 | * along with the ZBar Bar Code Reader; if not, write to the Free 18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * 21 | * http://sourceforge.net/projects/zbar 22 | *------------------------------------------------------------------------*/ 23 | 24 | #include "refcnt.h" 25 | 26 | #ifdef HAVE_LIBPTHREAD 27 | 28 | pthread_once_t initialized = PTHREAD_ONCE_INIT; 29 | pthread_mutex_t _zbar_reflock; 30 | 31 | static void initialize (void) 32 | { 33 | pthread_mutex_init(&_zbar_reflock, NULL); 34 | } 35 | 36 | void _zbar_refcnt_init () 37 | { 38 | pthread_once(&initialized, initialize); 39 | } 40 | 41 | 42 | #else 43 | 44 | void _zbar_refcnt_init () 45 | { 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /components/utils/qrcode/zbar/src/refcnt.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------ 2 | * Copyright 2007-2009 (c) Jeff Brown 3 | * 4 | * This file is part of the ZBar Bar Code Reader. 5 | * 6 | * The ZBar Bar Code Reader is free software; you can redistribute it 7 | * and/or modify it under the terms of the GNU Lesser Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * The ZBar Bar Code Reader is distributed in the hope that it will be 12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser Public License 17 | * along with the ZBar Bar Code Reader; if not, write to the Free 18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * 21 | * http://sourceforge.net/projects/zbar 22 | *------------------------------------------------------------------------*/ 23 | #ifndef _REFCNT_H_ 24 | #define _REFCNT_H_ 25 | 26 | #include "config.h" 27 | #include 28 | 29 | #if defined(_WIN32) 30 | # include 31 | 32 | typedef volatile LONG refcnt_t; /* FIXME where did volatile come from? */ 33 | 34 | static inline int _zbar_refcnt (refcnt_t *cnt, 35 | int delta) 36 | { 37 | int rc = -1; 38 | if(delta > 0) 39 | while(delta--) 40 | rc = InterlockedIncrement(cnt); 41 | else if(delta < 0) 42 | while(delta++) 43 | rc = InterlockedDecrement(cnt); 44 | assert(rc >= 0); 45 | return(rc); 46 | } 47 | 48 | 49 | #elif defined(HAVE_LIBPTHREAD) 50 | # include 51 | 52 | typedef int refcnt_t; 53 | 54 | extern pthread_mutex_t _zbar_reflock; 55 | 56 | static inline int _zbar_refcnt (refcnt_t *cnt, 57 | int delta) 58 | { 59 | pthread_mutex_lock(&_zbar_reflock); 60 | int rc = (*cnt += delta); 61 | pthread_mutex_unlock(&_zbar_reflock); 62 | assert(rc >= 0); 63 | return(rc); 64 | } 65 | 66 | 67 | #else 68 | 69 | typedef int refcnt_t; 70 | 71 | static inline int _zbar_refcnt (refcnt_t *cnt, 72 | int delta) 73 | { 74 | int rc = (*cnt += delta); 75 | assert(rc >= 0); 76 | return(rc); 77 | } 78 | 79 | #endif 80 | 81 | 82 | void _zbar_refcnt_init(void); 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /components/utils/qrcode/zbar/src/rs.h: -------------------------------------------------------------------------------- 1 | /*Copyright (C) 1991-1995 Henry Minsky (hqm@ua.com, hqm@ai.mit.edu) 2 | Copyright (C) 2008-2009 Timothy B. Terriberry (tterribe@xiph.org) 3 | You can redistribute this library and/or modify it under the terms of the 4 | GNU Lesser General Public License as published by the Free Software 5 | Foundation; either version 2.1 of the License, or (at your option) any later 6 | version.*/ 7 | #if !defined(_qrcode_rs_H) 8 | # define _qrcode_rs_H (1) 9 | 10 | /*This is one of 16 irreducible primitive polynomials of degree 8: 11 | x**8+x**4+x**3+x**2+1. 12 | Under such a polynomial, x (i.e., 0x02) is a generator of GF(2**8). 13 | The high order 1 bit is implicit. 14 | From~\cite{MD88}, Ch. 5, p. 275 by Patel. 15 | @BOOK{MD88, 16 | author="C. Dennis Mee and Eric D. Daniel", 17 | title="Video, Audio, and Instrumentation Recording", 18 | series="Magnetic Recording", 19 | volume=3, 20 | publisher="McGraw-Hill Education", 21 | address="Columbus, OH", 22 | month=Jun, 23 | year=1988 24 | }*/ 25 | #define QR_PPOLY (0x1D) 26 | 27 | /*The index to start the generator polynomial from (0...254).*/ 28 | #define QR_M0 (0) 29 | 30 | typedef struct rs_gf256 rs_gf256; 31 | 32 | struct rs_gf256{ 33 | /*A logarithm table in GF(2**8).*/ 34 | unsigned char log[256]; 35 | /*An exponential table in GF(2**8): exp[i] contains x^i reduced modulo the 36 | irreducible primitive polynomial used to define the field. 37 | The extra 256 entries are used to do arithmetic mod 255, since some extra 38 | table lookups are generally faster than doing the modulus.*/ 39 | unsigned char exp[511]; 40 | }; 41 | 42 | /*Initialize discrete logarithm tables for GF(2**8) using a given primitive 43 | irreducible polynomial.*/ 44 | void rs_gf256_init(rs_gf256 *_gf,unsigned _ppoly); 45 | 46 | /*Corrects a codeword with _ndata<256 bytes, of which the last _npar are parity 47 | bytes. 48 | Known locations of errors can be passed in the _erasures array. 49 | Twice as many (up to _npar) errors with a known location can be corrected 50 | compared to errors with an unknown location. 51 | Returns the number of errors corrected if successful, or a negative number if 52 | the message could not be corrected because too many errors were detected.*/ 53 | int rs_correct(const rs_gf256 *_gf,int _m0,unsigned char *_data,int _ndata, 54 | int _npar,const unsigned char *_erasures,int _nerasures); 55 | 56 | /*Create an _npar-coefficient generator polynomial for a Reed-Solomon code with 57 | _npar<256 parity bytes.*/ 58 | void rs_compute_genpoly(const rs_gf256 *_gf,int _m0, 59 | unsigned char *_genpoly,int _npar); 60 | 61 | /*Adds _npar<=_ndata parity bytes to an _ndata-_npar byte message. 62 | _data must contain room for _ndata<256 bytes.*/ 63 | void rs_encode(const rs_gf256 *_gf,unsigned char *_data,int _ndata, 64 | const unsigned char *_genpoly,int _npar); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /components/utils/qrcode/zbar/src/symbol.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------ 2 | * Copyright 2007-2009 (c) Jeff Brown 3 | * 4 | * This file is part of the ZBar Bar Code Reader. 5 | * 6 | * The ZBar Bar Code Reader is free software; you can redistribute it 7 | * and/or modify it under the terms of the GNU Lesser Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * The ZBar Bar Code Reader is distributed in the hope that it will be 12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser Public License 17 | * along with the ZBar Bar Code Reader; if not, write to the Free 18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, 19 | * Boston, MA 02110-1301 USA 20 | * 21 | * http://sourceforge.net/projects/zbar 22 | *------------------------------------------------------------------------*/ 23 | #ifndef _SYMBOL_H_ 24 | #define _SYMBOL_H_ 25 | 26 | #include 27 | #include "zbar.h" 28 | #include "refcnt.h" 29 | 30 | typedef struct point_s { 31 | int x, y; 32 | } point_t; 33 | 34 | struct zbar_symbol_set_s { 35 | refcnt_t refcnt; 36 | int nsyms; /* number of filtered symbols */ 37 | zbar_symbol_t *head; /* first of decoded symbol results */ 38 | zbar_symbol_t *tail; /* last of unfiltered symbol results */ 39 | }; 40 | 41 | struct zbar_symbol_s { 42 | zbar_symbol_type_t type; /* symbol type */ 43 | unsigned int data_alloc; /* allocation size of data */ 44 | unsigned int datalen; /* length of binary symbol data */ 45 | char *data; /* symbol data */ 46 | 47 | unsigned pts_alloc; /* allocation size of pts */ 48 | unsigned npts; /* number of points in location polygon */ 49 | point_t *pts; /* list of points in location polygon */ 50 | 51 | refcnt_t refcnt; /* reference count */ 52 | zbar_symbol_t *next; /* linked list of results (or siblings) */ 53 | zbar_symbol_set_t *syms; /* components of composite result */ 54 | unsigned long time; /* relative symbol capture time */ 55 | int cache_count; /* cache state */ 56 | int quality; /* relative symbol reliability metric */ 57 | }; 58 | 59 | extern void _zbar_symbol_free(zbar_symbol_t*); 60 | 61 | extern zbar_symbol_set_t *_zbar_symbol_set_create(void); 62 | extern void _zbar_symbol_set_free(zbar_symbol_set_t*); 63 | 64 | static inline void sym_add_point (zbar_symbol_t *sym, 65 | int x, 66 | int y) 67 | { 68 | int i = sym->npts; 69 | if(++sym->npts >= sym->pts_alloc) 70 | sym->pts = realloc(sym->pts, ++sym->pts_alloc * sizeof(point_t)); 71 | sym->pts[i].x = x; 72 | sym->pts[i].y = y; 73 | } 74 | 75 | static inline void _zbar_symbol_refcnt (zbar_symbol_t *sym, 76 | int delta) 77 | { 78 | if(!_zbar_refcnt(&sym->refcnt, delta) && delta <= 0) 79 | _zbar_symbol_free(sym); 80 | } 81 | 82 | static inline void _zbar_symbol_set_add (zbar_symbol_set_t *syms, 83 | zbar_symbol_t *sym) 84 | { 85 | sym->next = syms->head; 86 | syms->head = sym; 87 | syms->nsyms++; 88 | 89 | _zbar_symbol_refcnt(sym, 1); 90 | } 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /components/utils/qrcode/zbar/src/util.h: -------------------------------------------------------------------------------- 1 | /*Copyright (C) 2008-2009 Timothy B. Terriberry (tterribe@xiph.org) 2 | You can redistribute this library and/or modify it under the terms of the 3 | GNU Lesser General Public License as published by the Free Software 4 | Foundation; either version 2.1 of the License, or (at your option) any later 5 | version.*/ 6 | #if !defined(_qrcode_util_H) 7 | # define _qrcode_util_H (1) 8 | 9 | 10 | #define QR_MAXI(_a,_b) ((_a)-((_a)-(_b)&-((_b)>(_a)))) 11 | #define QR_MINI(_a,_b) ((_a)+((_b)-(_a)&-((_b)<(_a)))) 12 | #define QR_SIGNI(_x) (((_x)>0)-((_x)<0)) 13 | #define QR_SIGNMASK(_x) (-((_x)<0)) 14 | /*Unlike copysign(), simply inverts the sign of _a if _b is negative.*/ 15 | #define QR_FLIPSIGNI(_a,_b) ((_a)+QR_SIGNMASK(_b)^QR_SIGNMASK(_b)) 16 | #define QR_COPYSIGNI(_a,_b) QR_FLIPSIGNI(abs(_a),_b) 17 | /*Divides a signed integer by a positive value with exact rounding.*/ 18 | #define QR_DIVROUND(_x,_y) (((_x)+QR_FLIPSIGNI(_y>>1,_x))/(_y)) 19 | #define QR_CLAMPI(_a,_b,_c) (QR_MAXI(_a,QR_MINI(_b,_c))) 20 | #define QR_CLAMP255(_x) ((unsigned char)((((_x)<0)-1)&((_x)|-((_x)>255)))) 21 | /*Swaps two integers _a and _b if _a>_b.*/ 22 | #define QR_SORT2I(_a,_b) \ 23 | do{ \ 24 | int t__; \ 25 | t__=QR_MINI(_a,_b)^(_a); \ 26 | (_a)^=t__; \ 27 | (_b)^=t__; \ 28 | } \ 29 | while(0) 30 | #define QR_ILOG0(_v) (!!((_v)&0x2)) 31 | #define QR_ILOG1(_v) (((_v)&0xC)?2+QR_ILOG0((_v)>>2):QR_ILOG0(_v)) 32 | #define QR_ILOG2(_v) (((_v)&0xF0)?4+QR_ILOG1((_v)>>4):QR_ILOG1(_v)) 33 | #define QR_ILOG3(_v) (((_v)&0xFF00)?8+QR_ILOG2((_v)>>8):QR_ILOG2(_v)) 34 | #define QR_ILOG4(_v) (((_v)&0xFFFF0000)?16+QR_ILOG3((_v)>>16):QR_ILOG3(_v)) 35 | /*Computes the integer logarithm of a (positive, 32-bit) constant.*/ 36 | #define QR_ILOG(_v) ((int)QR_ILOG4((unsigned)(_v))) 37 | 38 | /*Multiplies 32-bit numbers _a and _b, adds (possibly 64-bit) number _r, and 39 | takes bits [_s,_s+31] of the result.*/ 40 | #define QR_FIXMUL(_a,_b,_r,_s) ((int)((_a)*(long long)(_b)+(_r)>>(_s))) 41 | /*Multiplies 32-bit numbers _a and _b, adds (possibly 64-bit) number _r, and 42 | gives all 64 bits of the result.*/ 43 | #define QR_EXTMUL(_a,_b,_r) ((_a)*(long long)(_b)+(_r)) 44 | 45 | unsigned qr_isqrt(unsigned _val); 46 | unsigned qr_ihypot(int _x,int _y); 47 | int qr_ilog(unsigned _val); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /components/utils/qrcode/zbar/src/zbar.c: -------------------------------------------------------------------------------- 1 | #include "zbar.h" 2 | 3 | #include "maix_qrcode.h" 4 | 5 | uint8_t buf[320 * 240]; 6 | 7 | // int Zbar_Test(uint16_t *imgbuf, int width, int height) 8 | 9 | /* return: 0:noqrcode other have qrcode */ 10 | uint8_t find_qrcodes(qrcode_image_t *img, qrcode_scan_t *scan, uint8_t convert) 11 | { 12 | /* 先申请内存,如果失败则直接返回 */ 13 | uint8_t *gray = malloc(img->w * img->h); 14 | if (!gray) 15 | { 16 | printk("malloc failed %s:%d\r\n", __func__, __LINE__); 17 | return 0; 18 | } 19 | 20 | /* 转换图像的字节序 */ 21 | qrcode_convert_order(img); 22 | /* 将图像转换为灰度 */ 23 | qrcode_convert_to_gray(img, gray); 24 | 25 | /* 开始调用Zbar进行扫码 */ 26 | /* create a reader */ 27 | zbar_image_scanner_t *scanner = zbar_image_scanner_create(); 28 | /* configure the reader */ 29 | zbar_image_scanner_set_config(scanner, 0, ZBAR_CFG_ENABLE, 1); 30 | /* wrap image data */ 31 | zbar_image_t *image = zbar_image_create(); 32 | zbar_image_set_format(image, *(int *)"Y800"); 33 | zbar_image_set_size(image, img->w, img->h); 34 | zbar_image_set_data(image, gray, img->w * img->h, NULL); //zbar_image_free_data 35 | /* scan the image for barcodes */ 36 | int qrcode_num = zbar_scan_image(scanner, image); 37 | /* extract results */ 38 | const zbar_symbol_t *symbol = zbar_image_first_symbol(image); 39 | 40 | /* 如果有多个二维码,会把最后一个结果返回 */ 41 | for (; symbol; symbol = zbar_symbol_next(symbol)) 42 | { 43 | /* do something useful with results */ 44 | zbar_symbol_type_t typ = zbar_symbol_get_type(symbol); 45 | const char *data = zbar_symbol_get_data(symbol); 46 | size_t len = strlen(data); 47 | 48 | printf("\r\ndecoded symbol: %s, content: \"%s\", len = %ld\r\n", zbar_get_symbol_name(typ), data, len); 49 | 50 | /* 拷贝到结果 */ 51 | if (len < QUIRC_MAX_PAYLOAD) 52 | { 53 | memcpy(scan->qrcode, data, len); 54 | scan->qrcode[len] = 0; 55 | } 56 | else 57 | { 58 | /* 这里溢出了,就不进行拷贝 */ 59 | qrcode_num = 0; 60 | } 61 | } 62 | 63 | /* clean up */ 64 | zbar_image_destroy(image); 65 | zbar_image_scanner_destroy(scanner); 66 | qrcode_convert_order(img); 67 | 68 | if (gray) 69 | free(gray); 70 | 71 | scan->qrcode_num = (uint8_t)qrcode_num; 72 | 73 | return qrcode_num; 74 | } 75 | -------------------------------------------------------------------------------- /components/utils/yuv_tab/include/yuv_tab.h: -------------------------------------------------------------------------------- 1 | #ifndef __YUV_TAB_H 2 | #define __YUV_TAB_H 3 | 4 | #include 5 | 6 | int8_t yuv_table(uint32_t idx); 7 | 8 | void pix_fill_yuv(uint32_t idx, int8_t *y, int8_t *u, int8_t *v); 9 | 10 | void pix_fill_8y(uint16_t *pixels, uint32_t ofs, int8_t *y); 11 | 12 | void pix_fill_8uv2(uint16_t *pixels, uint32_t ofs, int8_t *u, int8_t *v); 13 | 14 | void pix_fill_8yuv(uint16_t *pixels, uint32_t ofs, int8_t *y, int8_t *u, int8_t *v); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /projects/MF1/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | 3 | build 4 | .config.mk 5 | .flash.conf.json 6 | 7 | !/main/face_lib/lib/*.a -------------------------------------------------------------------------------- /projects/MF1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9) 2 | 3 | 4 | # Get SDK path 5 | if(NOT SDK_PATH) 6 | get_filename_component(SDK_PATH ../../ ABSOLUTE) 7 | if(EXISTS $ENV{MY_SDK_PATH}) 8 | set(SDK_PATH $ENV{MY_SDK_PATH}) 9 | endif() 10 | endif() 11 | 12 | # Check SDK Path 13 | if(NOT EXISTS ${SDK_PATH}) 14 | message(FATAL_ERROR "SDK path Error, Please set SDK_PATH or MY_SDK_PATH variable") 15 | endif() 16 | 17 | # Get Toolchain path 18 | if(NOT CONFIG_TOOLCHAIN_PATH) 19 | if(EXISTS $ENV{MY_TOOLCHAIN_PATH}) 20 | set(CONFIG_TOOLCHAIN_PATH $ENV{MY_TOOLCHAIN_PATH}) 21 | endif() 22 | endif() 23 | 24 | ## Add preprocessor definitions for whole project 25 | # add_definitions(-DAAAAA=1) 26 | 27 | # Call compile 28 | include(${SDK_PATH}/tools/cmake/compile.cmake) 29 | 30 | 31 | # Project Name 32 | project(MF1) 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /projects/MF1/compile/gen_binary.cmake: -------------------------------------------------------------------------------- 1 | 2 | execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crt0.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRT0_OBJ) 3 | execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtbegin.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRTBEGIN_OBJ) 4 | execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtend.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRTEND_OBJ) 5 | execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crti.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRTI_OBJ) 6 | execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtn.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRTN_OBJ) 7 | 8 | 9 | set(CMAKE_C_LINK_EXECUTABLE " \"${CRTI_OBJ}\" \"${CRTBEGIN_OBJ}\" \"${CRTEND_OBJ}\" \"${CRTN_OBJ}\" -o .elf -Wl,--start-group -Wl,--whole-archive -Wl,--no-whole-archive -Wl,--end-group") 10 | set(CMAKE_CXX_LINK_EXECUTABLE " \"${CRTI_OBJ}\" \"${CRTBEGIN_OBJ}\" \"${CRTEND_OBJ}\" \"${CRTN_OBJ}\" -o .elf -Wl,--start-group -Wl,--whole-archive -Wl,--no-whole-archive -Wl,--end-group") 11 | 12 | 13 | # Config toolchain 14 | if(CONFIG_TOOLCHAIN_PATH) 15 | set(CMAKE_SIZE "${CONFIG_TOOLCHAIN_PATH}/${CONFIG_TOOLCHAIN_PREFIX}size${EXT}") 16 | set(CMAKE_OBJDUMP "${CONFIG_TOOLCHAIN_PATH}/${CONFIG_TOOLCHAIN_PREFIX}objdump${EXT}") 17 | else() 18 | set(CMAKE_SIZE "size${EXT}") 19 | set(CMAKE_SIZE "objdump${EXT}") 20 | endif() 21 | 22 | # add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 23 | # COMMAND ${CMAKE_OBJCOPY} --output-format=binary ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.elf ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin 24 | # COMMENT "-- Generating .bin firmware at ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin" 25 | # ) 26 | 27 | # Build target 28 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 29 | # COMMAND ${CMAKE_OBJCOPY} --output-format=binary ${CMAKE_BINARY_DIR}/${PROJECT_NAME}${SUFFIX} --remove-section .iodata ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin 30 | COMMAND ${CMAKE_OBJCOPY} --output-format=binary ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.elf --remove-section .iodata ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin 31 | COMMENT "Generating .bin firmware at ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin") 32 | 33 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 34 | # COMMAND ${CMAKE_OBJCOPY} --output-format=binary ${CMAKE_BINARY_DIR}/${PROJECT_NAME}${SUFFIX} --only-section .iodata ${CMAKE_BINARY_DIR}/${PROJECT_NAME}_iodata.bin 35 | COMMAND ${CMAKE_OBJCOPY} --output-format=binary ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.elf --only-section .iodata ${CMAKE_BINARY_DIR}/${PROJECT_NAME}_iodata.bin 36 | COMMENT "Generating .bin file ...") 37 | 38 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 39 | COMMAND ${CMAKE_SIZE} ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.elf 40 | COMMENT "============= firmware =============" 41 | ) 42 | 43 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 44 | COMMAND ${CMAKE_OBJDUMP} -S ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.elf > ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.txt 45 | ) 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /projects/MF1/compile/priority.conf: -------------------------------------------------------------------------------- 1 | # component register priority 2 | # The upper components have higher priority 3 | # comments start with `#` 4 | 5 | 6 | kendryte_sdk 7 | main 8 | 9 | -------------------------------------------------------------------------------- /projects/MF1/config/config_defaults.mk.0: -------------------------------------------------------------------------------- 1 | CONFIG_LONG_PRESS_FUNCTION_KEY_CLEAR_FEATURE=n -------------------------------------------------------------------------------- /projects/MF1/config/config_defaults.mk.1: -------------------------------------------------------------------------------- 1 | CONFIG_LONG_PRESS_FUNCTION_KEY_CLEAR_FEATURE=y -------------------------------------------------------------------------------- /projects/MF1/config/config_defaults.mk.2: -------------------------------------------------------------------------------- 1 | CONFIG_LONG_PRESS_FUNCTION_KEY_CLEAR_FEATURE=n 2 | CONFIG_SHORT_PRESS_FUNCTION_KEY_RECORD_FACE=n 3 | -------------------------------------------------------------------------------- /projects/MF1/config/config_defaults.mk.3: -------------------------------------------------------------------------------- 1 | CONFIG_LONG_PRESS_FUNCTION_KEY_CLEAR_FEATURE=n 2 | CONFIG_LCD_HORIZONTAL=y 3 | CONFIG_LCD_WIDTH=320 -------------------------------------------------------------------------------- /projects/MF1/config_defaults.mk: -------------------------------------------------------------------------------- 1 | CONFIG_LONG_PRESS_FUNCTION_KEY_CLEAR_FEATURE=n -------------------------------------------------------------------------------- /projects/MF1/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ############### Add include ################### 2 | list(APPEND ADD_INCLUDE "include" 3 | "face_lib" 4 | "uart_recv" 5 | #esp8285 6 | "network/esp8285" 7 | "network/esp8285/http" 8 | "network/esp8285/mqtt" 9 | # "network/esp8285/qrcode" 10 | "network/esp8285/wifi" 11 | "network/esp8285/wifi/spi" 12 | "network/esp8285/wifi/utility" 13 | #w5500 14 | "network/w5500" 15 | "network/w5500/httpc" 16 | "network/w5500/httpd/src" 17 | "network/w5500/httpd/web_pages" 18 | "network/w5500/mqtt" 19 | "network/w5500/spi" 20 | "network/w5500/src" 21 | "network/w5500/src/utility" 22 | #sd_op 23 | "sd_op/include" 24 | ) 25 | # list(APPEND ADD_PRIVATE_INCLUDE "") 26 | ############################################### 27 | 28 | ############ Add source files ################# 29 | append_srcs_dir(ADD_SRCS "src") 30 | append_srcs_dir(ADD_SRCS "face_lib") 31 | append_srcs_dir(ADD_SRCS "uart_recv") 32 | 33 | if(CONFIG_ENABLE_SD_OTA) 34 | append_srcs_dir(ADD_SRCS "sd_op/src") 35 | list(APPEND ADD_REQUIREMENTS third_party) 36 | endif() 37 | 38 | if(CONFIG_NET_ENABLE) 39 | if(CONFIG_NET_ESP8285) 40 | message("-- Use ESP8285") 41 | FILE(GLOB_RECURSE NETWORK_SRC "network/esp8285/*.c") 42 | elseif(CONFIG_NET_W5500) 43 | message("-- Use W5500") 44 | FILE(GLOB_RECURSE NETWORK_SRC "network/w5500/*.c") 45 | endif() 46 | list(APPEND ADD_SRCS ${NETWORK_SRC}) 47 | endif() 48 | 49 | # aux_source_directory(src ADD_SRCS) 50 | # list(REMOVE_ITEM COMPONENT_SRCS "src/test2.c") 51 | ############################################### 52 | 53 | ###### Add required/dependent components ###### 54 | list(APPEND ADD_REQUIREMENTS kendryte_sdk drivers utils) 55 | ############################################### 56 | 57 | ############ Add static libs ################## 58 | 59 | # add_custom_command( PRE_BUILD 60 | if(CONFIG_LCD_VERTICAL AND 61 | (CONFIG_CAMERA_OV2640 OR CONFIG_CAMERA_GC0328_SINGLE)) 62 | message("-- Use lib_face_single_ver.a") 63 | list(APPEND ADD_STATIC_LIB "face_lib/lib/lib_face_single_ver.a") 64 | elseif(CONFIG_LCD_VERTICAL AND CONFIG_CAMERA_GC0328_DUAL) 65 | message("-- Use lib_face_dual_ver.a") 66 | list(APPEND ADD_STATIC_LIB "face_lib/lib/lib_face_dual_ver.a") 67 | elseif(NOT CONFIG_LCD_VERTICAL AND 68 | (CONFIG_CAMERA_OV2640 OR CONFIG_CAMERA_GC0328_SINGLE)) 69 | message("-- Use lib_face_single_hor.a") 70 | list(APPEND ADD_STATIC_LIB "face_lib/lib/lib_face_single_hor.a") 71 | elseif(NOT CONFIG_LCD_VERTICAL AND CONFIG_CAMERA_GC0328_DUAL) 72 | message("-- Use lib_face_dual_hor.a") 73 | list(APPEND ADD_STATIC_LIB "face_lib/lib/lib_face_dual_hor.a") 74 | endif() 75 | 76 | ############################################### 77 | 78 | 79 | register_component() 80 | -------------------------------------------------------------------------------- /projects/MF1/main/blur_detect/blur_detect.c: -------------------------------------------------------------------------------- 1 | #include "blur_detect.h" 2 | #include "stdlib.h" 3 | #include "math.h" 4 | 5 | float conv_data[9 * 3 * 3] = { 6 | //R 7 | 0,1,0,1,-4,1,0,1,0, 8 | 0,0,0,0,0,0,0,0,0, 9 | 0,0,0,0,0,0,0,0,0, 10 | //G 11 | 0,0,0,0,0,0,0,0,0, 12 | 0,1,0,1,-4,1,0,1,0, 13 | 0,0,0,0,0,0,0,0,0, 14 | //B 15 | 0,0,0,0,0,0,0,0,0, 16 | 0,0,0,0,0,0,0,0,0, 17 | 0,1,0,1,-4,1,0,1,0, 18 | }; 19 | 20 | volatile uint8_t g_conv_done_flag; 21 | 22 | conv_img_t conv_out_img; 23 | 24 | //plic_irq_callback_t 25 | static int kpu_done(void *ctx) 26 | { 27 | g_conv_done_flag = 1; 28 | return 0; 29 | } 30 | 31 | static kpu_task_t blur_detect_task; 32 | 33 | void blur_detect_init(uint16_t w, uint16_t h, uint8_t ch) 34 | { 35 | layer_conv_init(&blur_detect_task, w, h, ch, ch, conv_data); 36 | conv_out_img.w = w; 37 | conv_out_img.h = h; 38 | conv_out_img.ch = ch; 39 | conv_out_img.buf = malloc(sizeof(uint8_t) * ch * w * h); 40 | } 41 | 42 | float blur_detect_run(uint8_t *buf_in) 43 | { 44 | float result = 0; 45 | layer_conv_run(&blur_detect_task, buf_in, conv_out_img.buf, kpu_done); 46 | while (!g_conv_done_flag); 47 | g_conv_done_flag = 0; 48 | result = clc_variance(&conv_out_img); 49 | return result; 50 | } 51 | 52 | static float clc_variance(conv_img_t *conv_img) 53 | { 54 | uint8_t ch_mean[conv_img->ch]; 55 | uint64_t ch_sum[conv_img->ch]; 56 | uint64_t ch_variance[conv_img->ch]; 57 | float result = 0; 58 | for (int i = 0; i < conv_img->ch; i++) 59 | { 60 | ch_mean[i] = 0; 61 | ch_variance[i] = 0; 62 | } 63 | uint32_t img_size = conv_img->w * conv_img->h; 64 | 65 | for (int i = 0; i < conv_img->ch; i++) 66 | { 67 | for (uint32_t j = 0; j < img_size; j++) 68 | { 69 | ch_sum[i] += conv_img->buf[j * conv_img->ch + i]; 70 | } 71 | ch_mean[i] = ch_sum[i]/img_size; 72 | } 73 | 74 | for (int i = 0; i < conv_img->ch; i++) 75 | { 76 | for (uint32_t j = 0; j < img_size; j++) 77 | { 78 | ch_variance[i] += (ch_mean[i] - (conv_img->buf[j * conv_img->ch + i])) * (ch_mean[i] - (conv_img->buf[j * conv_img->ch + i])); 79 | } 80 | ch_variance[i] /= img_size; 81 | } 82 | for (int i = 0; i < conv_img->ch; i++) 83 | { 84 | result += ch_variance[i] / ch_mean[i]; 85 | } 86 | result /= conv_img->ch; 87 | 88 | return result; 89 | } 90 | 91 | void blur_detect_deinit() 92 | { 93 | 94 | free(conv_out_img.buf); 95 | } -------------------------------------------------------------------------------- /projects/MF1/main/blur_detect/blur_detect.h: -------------------------------------------------------------------------------- 1 | #include "kpu.h" 2 | #include "layer.h" 3 | 4 | typedef struct 5 | { 6 | uint16_t w; 7 | uint16_t h; 8 | uint8_t ch; 9 | uint8_t *buf; 10 | } conv_img_t; 11 | 12 | void blur_detect_init(uint16_t w, uint16_t h, uint8_t ch); 13 | float blur_detect_run(uint8_t *buf_in); 14 | void blur_detect_deinit(); 15 | 16 | -------------------------------------------------------------------------------- /projects/MF1/main/blur_detect/layer.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Sipeed Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _LAYER_H 17 | #define _LAYER_H 18 | 19 | void layer_conv_init(kpu_task_t *task, uint16_t w, uint16_t h, uint8_t ch_in, uint8_t ch_out, float *conv_data); 20 | void layer_conv_run(kpu_task_t *task, uint8_t *img_src, uint8_t *img_dst, plic_irq_callback_t callback); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /projects/MF1/main/face_lib/face_cb.h: -------------------------------------------------------------------------------- 1 | #ifndef __FACE_CB_H 2 | #define __FACE_CB_H 3 | 4 | #include "stdint.h" 5 | 6 | #include "face_lib.h" 7 | 8 | extern uint8_t delay_flag; 9 | extern uint8_t lcd_bl_stat; 10 | 11 | void face_cb_init(void); 12 | 13 | void convert_320x240_to_240x240(uint8_t *img_320, uint16_t x_offset); 14 | 15 | void lcd_display_image_alpha(uint32_t pic_addr, uint32_t alpha); 16 | 17 | void lcd_draw_pass(void); 18 | 19 | uint8_t judge_face_by_keypoint(key_point_t *kp); 20 | uint8_t check_front_face(key_point_t *kp); 21 | void protocol_record_face(proto_record_face_cfg_t *cfg); 22 | 23 | void detected_face_cb(face_recognition_ret_t *face); 24 | void fake_face_cb(face_recognition_ret_t *face); 25 | void pass_face_cb(face_recognition_ret_t *face, uint8_t ir_check); 26 | 27 | void lcd_refresh_cb(void); 28 | void lcd_convert_cb(void); 29 | void lcd_close_bl_cb(void); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /projects/MF1/main/face_lib/lcd_dis.h: -------------------------------------------------------------------------------- 1 | #ifndef __LCD_DIS_H 2 | #define __LCD_DIS_H 3 | 4 | #include 5 | #include "list.h" 6 | 7 | /* clang-format off */ 8 | enum{ 9 | DIS_TYPE_STR=0, 10 | DIS_TYPE_PIC, 11 | }; 12 | 13 | typedef struct 14 | { 15 | uint16_t x; 16 | uint16_t y; 17 | 18 | uint16_t color; 19 | uint16_t bg_color; 20 | 21 | uint16_t zh_CN; 22 | uint16_t size; 23 | 24 | char *str;//must malloc 25 | }dis_str_t; 26 | 27 | typedef struct 28 | { 29 | uint16_t x; 30 | uint16_t y; 31 | uint16_t w; 32 | uint16_t h; 33 | uint32_t flash_addr; 34 | uint32_t alpha; 35 | }dis_pic_t; 36 | 37 | typedef struct 38 | { 39 | int id; 40 | int type;//0:str,1:pic 41 | int auto_del; 42 | void * dis; 43 | }lcd_dis_t; 44 | /* clang-format on */ 45 | /////////////////////////////////////////////////////////////////////////////// 46 | 47 | extern list_t *lcd_dis_list; 48 | /////////////////////////////////////////////////////////////////////////////// 49 | uint8_t lcd_dis_list_init(void); 50 | void lcd_dis_list_del_all(void); 51 | int lcd_dis_list_del_by_id(int id); 52 | void lcd_dis_list_free(lcd_dis_t *lcd_dis); 53 | 54 | void lcd_dis_list_display(uint8_t *image, uint16_t img_w, uint16_t img_h, lcd_dis_t *lcd_dis); 55 | 56 | lcd_dis_t *lcd_dis_list_add_str(int id, int auto_del, uint16_t size, uint16_t zh_CN, 57 | char *str, uint16_t x, uint16_t y, 58 | uint16_t color, uint16_t bg_color); 59 | 60 | lcd_dis_t *lcd_dis_list_add_pic(int id, int auto_del, 61 | uint32_t addr, uint32_t alpha, 62 | uint16_t x, uint16_t y, 63 | uint16_t w, uint16_t h); 64 | 65 | uint8_t lcd_dis_get_zhCN_dat(uint8_t *zhCN_char, uint8_t *zhCN_dat, uint8_t size); 66 | 67 | /////////////////////////////////////////////////////////////////////////////// 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /projects/MF1/main/face_lib/lib/lib_face_dual_hor.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/projects/MF1/main/face_lib/lib/lib_face_dual_hor.a -------------------------------------------------------------------------------- /projects/MF1/main/face_lib/lib/lib_face_dual_ver.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/projects/MF1/main/face_lib/lib/lib_face_dual_ver.a -------------------------------------------------------------------------------- /projects/MF1/main/face_lib/lib/lib_face_single_hor.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/projects/MF1/main/face_lib/lib/lib_face_single_hor.a -------------------------------------------------------------------------------- /projects/MF1/main/face_lib/lib/lib_face_single_ver.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/projects/MF1/main/face_lib/lib/lib_face_single_ver.a -------------------------------------------------------------------------------- /projects/MF1/main/include/board.h: -------------------------------------------------------------------------------- 1 | #ifndef _BOARD_H 2 | #define _BOARD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "face_lib.h" 10 | #include "system_config.h" 11 | 12 | #define RLED 1 13 | #define GLED 2 14 | #define BLED 4 15 | 16 | #define PLL0_OUTPUT_FREQ 800000000UL 17 | #define PLL1_OUTPUT_FREQ 400000000UL 18 | 19 | extern volatile uint8_t g_key_press; 20 | extern volatile uint8_t g_key_long_press; 21 | 22 | extern uint8_t sKey_dir; 23 | #if 0 24 | #if (!CONFIG_CAMERA_OV2640 || !CONFIG_CAMERA_GC0328_SINGLE) 25 | extern uint8_t kpu_image_tmp[CONFIG_CAMERA_RESOLUTION_WIDTH * CONFIG_CAMERA_RESOLUTION_HEIGHT * 3]; 26 | #endif 27 | 28 | #if CONFIG_LCD_VERTICAL 29 | extern uint8_t display_image_ver[CONFIG_CAMERA_RESOLUTION_WIDTH * CONFIG_CAMERA_RESOLUTION_HEIGHT * 2]; //显示 30 | #endif 31 | 32 | extern uint8_t kpu_image[2][CONFIG_CAMERA_RESOLUTION_WIDTH * CONFIG_CAMERA_RESOLUTION_HEIGHT * 3]; 33 | extern uint8_t display_image[CONFIG_CAMERA_RESOLUTION_WIDTH * CONFIG_CAMERA_RESOLUTION_HEIGHT * 2]; 34 | #else 35 | extern uint8_t kpu_image[2][CONFIG_CAMERA_RESOLUTION_WIDTH * CONFIG_CAMERA_RESOLUTION_HEIGHT * 3]; 36 | extern uint8_t rgb_image[2][CONFIG_CAMERA_RESOLUTION_WIDTH * CONFIG_CAMERA_RESOLUTION_HEIGHT * 2]; 37 | #define display_image (rgb_image[rgb_buf_index]) 38 | #endif 39 | int irq_gpiohs(void *ctx); 40 | 41 | void set_IR_LED(int state); 42 | void set_W_LED(int state); 43 | void set_lcd_bl(int stat); 44 | 45 | void set_RGB_LED(int state); 46 | 47 | void update_key_state(void); 48 | void board_init(void); 49 | 50 | void web_set_RGB_LED(uint8_t val[3]); 51 | 52 | #endif -------------------------------------------------------------------------------- /projects/MF1/main/include/core1.h: -------------------------------------------------------------------------------- 1 | #ifndef __CORE1_H 2 | #define __CORE1_H 3 | 4 | #include 5 | 6 | #include "global_config.h" 7 | 8 | #if CONFIG_ENABLE_OUTPUT_JPEG 9 | 10 | #include "cQueue.h" 11 | 12 | /* clang-format off */ 13 | typedef enum _net_task_type 14 | { 15 | TASK_UPLOAD = (0), 16 | 17 | TASK_CAL_PIC_FEA = (2), 18 | TASK_CAL_PIC_FEA_RES = (3), 19 | 20 | } net_task_type_t; 21 | 22 | /* clang-format on */ 23 | 24 | typedef struct _net_task 25 | { 26 | net_task_type_t task_type; 27 | void *task_data; 28 | } net_task_t; 29 | 30 | typedef struct _upload_face_pic 31 | { 32 | uint8_t *jpeg_addr; 33 | uint32_t jpeg_len; 34 | 35 | } upload_face_pic_t; 36 | 37 | /* clang-format on */ 38 | extern volatile Queue_t q_core1; 39 | 40 | void send_jpeg_to_core1(uint8_t *image); 41 | int core1_function(void *ctx); 42 | 43 | #endif /* CONFIG_ENABLE_OUTPUT_JPEG */ 44 | #endif /* __CORE1_H */ 45 | -------------------------------------------------------------------------------- /projects/MF1/main/include/system_config.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYSTEM_CONFIG_H 2 | #define _SYSTEM_CONFIG_H 3 | 4 | #include "uart.h" 5 | #include "global_config.h" 6 | 7 | /* clang-format off */ 8 | /////////////////////////////////////////////////////////////////////////////// 9 | #define LOCK_IN_SECTION(s) __attribute__((used,unused,section(".iodata." #s))) 10 | 11 | #define LCD_OFT (40) 12 | 13 | /////////////////////////////////////////////////////////////////////////////// 14 | #define DBG_UART_NUM (UART_DEV3) //maybe bug 15 | #define PROTOCOL_UART_NUM (UART_DEV1) 16 | 17 | /////////////////////////////////////////////////////////////////////////////// 18 | /* CAMERA */ 19 | #define CAM_SCL_PIN (41) 20 | #define CAM_SDA_650_PIN (42) 21 | #define CAM_SDA_850_PIN (40) 22 | /////////////////////////////////////////////////////////////////////////////// 23 | 24 | //Note: Address must 4KB align 25 | /////////////////////////////////////////////////////////////////////////////// 26 | #define FONT_16x16_ADDR (0x70C000) 27 | #define FONT_32x32_ADDR (0xA00000) 28 | 29 | #define BOARD_CFG_ADDR (0x7FF000) //8M-4K 30 | #define BOARD_CFG_LEN (4 * 1024) 31 | #define WATCH_DOG_TIMEOUT (20000) //ms 32 | 33 | //Face log 2M~3M 34 | #define DATA_ADDRESS (0x800000) //size=0x1000, 4KB,32768人 35 | #define UID_LEN (16) 36 | #define NAME_LEN (16) 37 | #define NOTE_LEN (16) 38 | // #define UID_TABLE_SIZE (0x4000) //实际预留4096人,即64KB 39 | #define FACE_DATA_ADDERSS (0x810000) //8M+64K 40 | #define FACE_HEADER (0x55AA5503) 41 | #define FACE_DATA_MAX_COUNT (512) 42 | /////////////////////////////////////////////////////////////////////////////// 43 | //UI IMAGE reserve 192KB for potential QVGA rgb565 44 | #define IMG_LCD_SIZE (240*240*2) 45 | #define IMG_RECORD_FACE_ADDR (0xC00000) 46 | #define IMG_FACE_PASS_ADDR (IMG_RECORD_FACE_ADDR + (116 * 1024 * 1)) 47 | #define IMG_CONNING_ADDR (IMG_RECORD_FACE_ADDR + (116 * 1024 * 2)) 48 | #define IMG_CONN_FAILED_ADDR (IMG_RECORD_FACE_ADDR + (116 * 1024 * 3)) 49 | #define IMG_CONN_SUCC_ADDR (IMG_RECORD_FACE_ADDR + (116 * 1024 * 4)) 50 | #define IMG_SCAN_QR_ADDR (IMG_RECORD_FACE_ADDR + (116 * 1024 * 5)) 51 | #define IMG_QR_TIMEOUT_ADDR (IMG_RECORD_FACE_ADDR + (116 * 1024 * 6)) 52 | /////////////////////////////////////////////////////////////////////////////// 53 | // AUDIO DATA 54 | #define AUDIO_PASS_ADDR (0xE00000) 55 | #define AUDIO_PASS_SIZE (36096) 56 | /* clang-format on */ 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /projects/MF1/main/include/user_cmd.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_CMD_H 2 | #define __USER_CMD_H 3 | 4 | #include "global_config.h" 5 | 6 | #include 7 | 8 | #include "face_lib.h" 9 | 10 | /////////////////////////////////////// 11 | #if CONFIG_NOTIFY_STRANGER 12 | extern protocol_custom_cb_t user_custom_cmd[4]; 13 | #else 14 | extern protocol_custom_cb_t user_custom_cmd[3]; 15 | #endif 16 | /////////////////////////////////////// 17 | extern int proto_scan_qrcode_flag; 18 | extern uint8_t proto_start_face_recon_flag; 19 | 20 | void proto_qrcode_scan_loop(void); 21 | 22 | /////////////////////////////////////// 23 | 24 | #endif /* __USER_CMD_H */ 25 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/demo_esp8285.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEMO_ESP8285_h 2 | #define __DEMO_ESP8285_h 3 | 4 | #include "global_config.h" 5 | 6 | /* clang-format off */ 7 | #if CONFIG_NET_ENABLE 8 | #if CONFIG_NET_ESP8285 9 | #define CONFIG_KEY_SHORT_QRCODE (1) 10 | #define CONFIG_NET_DEMO_MQTT (1) 11 | #define CONFIG_NET_DEMO_HTTP_GET (1) 12 | #define CONFIG_NET_DEMO_HTTP_POST (1) 13 | #endif 14 | #endif 15 | /* clang-format on */ 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/http/http_file.h: -------------------------------------------------------------------------------- 1 | #ifndef __HTTP_GET_FILE_H 2 | #define __HTTP_GET_FILE_H 3 | 4 | uint32_t http_get_file(char *url, 5 | char *custom_headers, 6 | char *resp_header, 7 | uint32_t resp_header_len, 8 | uint8_t *file, 9 | uint32_t file_len); 10 | 11 | uint32_t http_post_file(char *url, 12 | char *custom_headers, 13 | uint8_t *body, 14 | uint8_t *boundary, 15 | uint8_t *post_file, 16 | uint32_t post_file_len, 17 | char *resp_header, 18 | uint32_t resp_header_len, 19 | uint8_t *file, 20 | uint32_t file_len); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/http/http_save_file.h: -------------------------------------------------------------------------------- 1 | #ifndef __HTTP_SAVE_FILE_H 2 | #define __HTTP_SAVE_FILE_H 3 | 4 | #define DEBUG_HTTP_TIME 0 5 | 6 | uint32_t http_save_file(uint8_t sock, char *resp_header, uint32_t resp_header_len, uint8_t *file, uint32_t file_len); 7 | 8 | #endif -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/http/http_simple.h: -------------------------------------------------------------------------------- 1 | #ifndef __HTTP_SIMPLE_H 2 | #define __HTTP_SIMPLE_H 3 | 4 | /* 5 | Represents an HTTP html response 6 | */ 7 | struct http_response 8 | { 9 | struct parsed_url *request_uri; 10 | char *body; 11 | uint32_t body_len; 12 | char *status_code; 13 | int status_code_int; 14 | char *status_text; 15 | char *request_headers; 16 | char *response_headers; 17 | }; 18 | 19 | struct http_response *http_get(char *url, char *custom_headers); 20 | struct http_response *http_post(char *url, char *custom_headers, char *post_data); 21 | 22 | char* http_get_header_filed(char *header, char *filed); 23 | 24 | void http_response_free(struct http_response *hresp); 25 | 26 | #endif -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/http/my_str.h: -------------------------------------------------------------------------------- 1 | #ifndef __MY_STR_H 2 | #define __MY_STR_H 3 | 4 | // int my_atoi(char *string); 5 | 6 | int my_isalpha(int ch); 7 | char my_isdigit(unsigned char c); 8 | int my_isalnum(int c); 9 | int my_str_index_of(const char *a, char *b); 10 | int my_str_contains(const char *haystack, const char *needle); 11 | char *my_trim_end(char *string, char to_trim); 12 | char *my_str_cat(char *a, char *b); 13 | char my_to_hex(char code); 14 | char *my_urlencode(char *str); 15 | char *my_str_ndup(const char *str, size_t max); 16 | char *my_str_dup(const char *src); 17 | char *my_str_replace(char *search, char *replace, char *subject); 18 | char *my_get_until(char *haystack, char *until); 19 | void my_decodeblock(unsigned char in[], char *clrstr); 20 | char *my_base64_decode(char *b64src); 21 | void my_encodeblock(unsigned char in[], char b64str[], int len); 22 | char *my_base64_encode(char *clrstr); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/http/parsed_url.h: -------------------------------------------------------------------------------- 1 | #ifndef __PARSED_URL_H 2 | #define __PARSED_URL_H 3 | 4 | #define NOT_ONLY_SUPPORT_GET 0 5 | 6 | struct parsed_url 7 | { 8 | char *uri; /* mandatory */ 9 | char *scheme; /* mandatory */ 10 | char *host; /* mandatory */ 11 | char *ip; /* mandatory */ 12 | char *port; /* optional */ 13 | char *path; /* optional */ 14 | char *query; /* optional */ 15 | #if NOT_ONLY_SUPPORT_GET 16 | char *fragment; /* optional */ 17 | char *username; /* optional */ 18 | char *password; /* optional */ 19 | #endif 20 | }; 21 | 22 | void parsed_url_free(struct parsed_url *purl); 23 | struct parsed_url *parse_url(const char *url); 24 | 25 | #endif -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/net_8285.h: -------------------------------------------------------------------------------- 1 | #ifndef __NET_8285_H 2 | #define __NET_8285_H 3 | 4 | #include 5 | #include 6 | 7 | //mqtt 8 | #include "PubSubClient.h" 9 | 10 | /* clang-format off */ 11 | /* clang-format on */ 12 | 13 | enum 14 | { 15 | QRCODE_RET_CODE_OK, /* 0 */ 16 | QRCODE_RET_CODE_NO_DATA, /* 1 */ 17 | QRCODE_RET_CODE_PRASE_ERR, /* 2 */ 18 | QRCODE_RET_CODE_TIMEOUT /* 3 */ 19 | }; 20 | 21 | typedef struct _qr_wifi_info 22 | { 23 | uint8_t ret; 24 | 25 | char ssid[32]; 26 | char passwd[32]; 27 | } qr_wifi_info_t; 28 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 29 | 30 | extern volatile uint8_t g_net_status; 31 | extern volatile uint8_t qrcode_get_info_flag; 32 | extern uint64_t qrcode_start_time; 33 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 34 | 35 | qr_wifi_info_t *qrcode_get_wifi_cfg(void); 36 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 37 | uint8_t spi_8266_init_device(void); 38 | uint8_t spi_8266_connect_ap(uint8_t wifi_ssid[32], 39 | uint8_t wifi_passwd[32], 40 | uint8_t timeout_n10s); 41 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 42 | void mqtt_reconnect(void); 43 | uint8_t spi_8266_mqtt_init(void); 44 | void spi_8266_mqtt_send(char *buf,size_t len); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/wifi/WiFiSpiClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | WiFiSpiClient.h - Library for Arduino with ESP8266 as slave. 3 | Copyright (c) 2017 Jiri Bilek. All right reserved. 4 | 5 | --- 6 | 7 | Based on WiFiClient.h - Library for Arduino Wifi shield. 8 | Copyright (c) 2011-2014 Arduino LLC. All right reserved. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _WIFISPICLIENT_H_INCLUDED 26 | #define _WIFISPICLIENT_H_INCLUDED 27 | 28 | #include 29 | 30 | #include "printf.h" 31 | 32 | #include "wifispi_drv.h" 33 | 34 | uint8_t WiFiSpiClient_connect_host(const char *host, uint16_t port,uint8_t isSSL); 35 | uint8_t WiFiSpiClient_connect_ip(IPAddress_t ip, uint16_t port,uint8_t isSSL); 36 | 37 | size_t WiFiSpiClient_write(uint8_t sock, const uint8_t *buf, size_t size); 38 | int WiFiSpiClient_available(uint8_t sock); 39 | int WiFiSpiClient_read_oneByte(uint8_t sock); 40 | int WiFiSpiClient_read_buf(uint8_t sock, uint8_t *buf, size_t size); 41 | int WiFiSpiClient_peek(uint8_t sock); 42 | void WiFiSpiClient_flush(uint8_t sock); 43 | void WiFiSpiClient_stop(uint8_t sock); 44 | uint8_t WiFiSpiClient_connected(uint8_t sock); 45 | uint8_t WiFiSpiClient_status(uint8_t sock); 46 | uint8_t WiFiSpiClient_verifySSL(uint8_t sock, uint8_t *fingerprint, const char *host); 47 | #endif 48 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/wifi/WiFiSpiServer.c: -------------------------------------------------------------------------------- 1 | // /* 2 | // WiFiSPIServer.cpp - Library for Arduino Wifi SPI connection with ESP8266. 3 | // Copyright (c) 2017 Jiri Bilek. All right reserved. 4 | 5 | // --- 6 | 7 | // Based on WiFiServer.cpp - Library for Arduino Wifi shield. 8 | // Copyright (c) 2011-2014 Arduino LLC. All right reserved. 9 | 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | // */ 24 | 25 | // #include 26 | // #include "srvspi_drv.h" 27 | 28 | // #include "WiFiSpi.h" 29 | // #include "WiFiSpiClient.h" 30 | // #include "WiFiSpiServer.h" 31 | 32 | // static uint16_t _port; 33 | // static void *pcb; 34 | // static uint8_t _sock; 35 | 36 | // /* 37 | // * 38 | // */ 39 | // void WiFiSpiServer_begin(uint16_t port) 40 | // { 41 | // uint8_t sock = WiFiSpi_getSocket(); 42 | 43 | // if (sock != SOCK_NOT_AVAIL) 44 | // { 45 | // _sock = sock; 46 | // ServerSpiDrv_startServer(_port, _sock); 47 | // WiFiSpi_server_port[_sock] = _port; 48 | // WiFiSpi_state[_sock] = _sock; 49 | // } 50 | // } 51 | 52 | // /* 53 | // * 54 | // */ 55 | // WiFiSpiClient WiFiSpiServer_available(uint8_t *status) 56 | // { 57 | // WiFiSpiClient client(_sock); 58 | 59 | // uint8_t _client_status = client.status(); // creates Client object on ESP side if there is established connection 60 | // // uint8_t _server_status = this->status(); removed, may be related with the comment below, running fine without it 61 | 62 | // if (status != NULL) 63 | // *status = _client_status; 64 | 65 | // // TODO: If server is not in listen state, restart it (code present in original WiFiServer.h). I think it is useless. 66 | 67 | // if (_client_status == ESTABLISHED) 68 | // return client; 69 | 70 | // return WiFiSpiClient(SOCK_NOT_AVAIL); // closed Client 71 | // } 72 | 73 | // /* 74 | // * 75 | // */ 76 | // uint8_t WiFiSpiServer_status() 77 | // { 78 | // return ServerSpiDrv_getServerState(0); 79 | // } 80 | 81 | // // /* 82 | // // * 83 | // // */ 84 | // // size_t WiFiSpiServer_write(uint8_t b) 85 | // // { 86 | // // return write(&b, 1); 87 | // // } 88 | 89 | // /* 90 | // * 91 | // */ 92 | // size_t WiFiSpiServer_write(const uint8_t *buffer, size_t size) 93 | // { 94 | // size_t n = 0; 95 | // WiFiSpiClient client(_sock); 96 | 97 | // if (client.status() == ESTABLISHED) 98 | // n = client.write(buffer, size); 99 | 100 | // return n; 101 | // } 102 | 103 | // /* 104 | // * 105 | // */ 106 | // void WiFiSpiServer_stop() 107 | // { 108 | // ServerSpiDrv_stopServer(_sock); 109 | 110 | // WiFiSpi_server_port[_sock] = 0; 111 | // WiFiSpi_state[_sock] = NA_STATE; 112 | // } 113 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/wifi/WiFiSpiServer.h: -------------------------------------------------------------------------------- 1 | // /* 2 | // WiFiSPIServer.h - Library for Arduino Wifi SPI connection with ESP8266. 3 | // Copyright (c) 2017 Jiri Bilek. All right reserved. 4 | 5 | // --- 6 | 7 | // Based on WiFiServer.h - Library for Arduino Wifi shield. 8 | // Copyright (c) 2011-2014 Arduino LLC. All right reserved. 9 | 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2.1 of the License, or (at your option) any later version. 14 | 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the Free Software 22 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | // */ 24 | 25 | // #ifndef _WIFISPISERVER_H_INCLUDED 26 | // #define _WIFISPISERVER_H_INCLUDED 27 | 28 | // #include "wl_definitions.h" 29 | 30 | // #endif 31 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/wifi/WiFiSpiUdp.h: -------------------------------------------------------------------------------- 1 | /* 2 | WiFiSPIUdp.h - Library for Arduino Wifi SPI connection with ESP8266. 3 | Copyright (c) 2017 Jiri Bilek. All right reserved. 4 | 5 | --- 6 | 7 | Based on WiFiUdp.h - Library for Arduino Wifi shield. 8 | Copyright (c) 2011-2014 Arduino LLC. All right reserved. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _WIFISPIUDP_H_INCLUDED 26 | #define _WIFISPIUDP_H_INCLUDED 27 | 28 | #include 29 | #include 30 | #include "wifispi_drv.h" 31 | 32 | #define UDP_TX_PACKET_MAX_SIZE 24 33 | 34 | uint8_t WiFiSpiUdp_begin(uint16_t port); 35 | int WiFiSpiUdp_available(uint8_t sock); 36 | void WiFiSpiUdp_stop(uint8_t sock); 37 | int WiFiSpiUdp_beginPacket(uint8_t sock, const char *host, uint16_t port); 38 | int WiFiSpiUdp_beginPacket_ipaddr(uint8_t sock, IPAddress_t ip, uint16_t port); 39 | int WiFiSpiUdp_endPacket(uint8_t sock); 40 | size_t WiFiSpiUdp_write_oneByte(uint8_t sock, uint8_t byte); 41 | size_t WiFiSpiUdp_write_buf(uint8_t sock, const uint8_t *buffer, size_t size); 42 | int WiFiSpiUdp_parsePacket(uint8_t sock); 43 | int WiFiSpiUdp_read_oneByte(uint8_t sock); 44 | int WiFiSpiUdp_read_buf(uint8_t sock, unsigned char *buffer, size_t len); 45 | int WiFiSpiUdp_peek(uint8_t sock); 46 | void WiFiSpiUdp_flush(uint8_t sock); 47 | IPAddress_t WiFiSpiUdp_remoteIP(uint8_t sock); 48 | uint16_t WiFiSpiUdp_remotePort(uint8_t sock); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/wifi/spi/myspi.h: -------------------------------------------------------------------------------- 1 | #ifndef __MYSPI_H 2 | #define __MYSPI_H 3 | 4 | #include 5 | 6 | void my_spi_cs_set(void); 7 | void my_spi_cs_clr(void); 8 | 9 | void my_spi_init(void); 10 | uint8_t my_spi_rw(uint8_t data); 11 | void my_spi_rw_len(uint8_t *send, uint8_t *recv, uint32_t len); 12 | uint64_t get_millis(void); 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/wifi/utility/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | config.h - Library for Arduino SPI connection to ESP8266 3 | Copyright (c) 2019 Jiri Bilek. All rights reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | ----------------------------------------------------- 20 | 21 | This file is a "center of configuration options". All important options for the 22 | library are concentrated here. 23 | */ 24 | 25 | #ifndef __CONFIG_H 26 | #define __CONFIG_H 27 | 28 | // Uncomment the following define if the safe reset circuit (https://github.com/JiriBilek/WiFiSpiESP/issues/6) 29 | // is connected to SS pin on ESP8266. This allows the SS signal to behave exactly 30 | // according SPI specification (goes low before transmission and high after) 31 | #define ESP8266_SAFE_RESET_IMPLEMENTED 32 | 33 | // Allow debugging information to be print on Serial 34 | #define ESPSPI_DEBUG_OPTION 35 | 36 | // Print information about received bad message on Serial 37 | //#define ESPSPI_DEBUG_OPTION_BAD_MESSAGE 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/wifi/utility/espspi_drv.h: -------------------------------------------------------------------------------- 1 | /* 2 | espspi_drv.h - Library for Arduino SPI connection with ESP8266 3 | 4 | Copyright (c) 2017 Jiri Bilek. All right reserved. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | #ifndef _ESPSPI_DRV_H_INCLUDED 22 | #define _ESPSPI_DRV_H_INCLUDED 23 | 24 | #include "wifi_spi.h" 25 | #include "wifispi_drv.h" 26 | #include "espspi_proxy.h" 27 | 28 | #define WAIT_FOR_SLAVE_RX_READY() \ 29 | EspSpiProxy_waitForSlaveRxReady(); 30 | 31 | #define WAIT_FOR_SLAVE_TX_READY() \ 32 | EspSpiProxy_waitForSlaveTxReady(); 33 | 34 | void EspSpiDrv_sendCmd(const uint8_t cmd, const uint8_t numParam); 35 | void EspSpiDrv_endCmd(); 36 | void EspSpiDrv_sendParam(const uint8_t *param, const uint8_t param_len); 37 | // void EspSpiDrv_sendParam(const uint8_t param); 38 | void EspSpiDrv_sendBuffer(const uint8_t *param, uint16_t param_len); 39 | uint8_t EspSpiDrv_waitResponseCmd(const uint8_t cmd, uint8_t numParam, uint8_t *param, uint8_t *param_len); 40 | uint8_t EspSpiDrv_waitResponseCmd16(const uint8_t cmd, uint8_t numParam, uint8_t *param, uint16_t *param_len); 41 | int8_t EspSpiDrv_waitResponseParams(const uint8_t cmd, uint8_t numParam, tParam_t *params); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/wifi/utility/espspi_proxy.h: -------------------------------------------------------------------------------- 1 | /* 2 | espspi_proxy.h - Library for Arduino SPI connection with ESP8266 3 | 4 | Copyright (c) 2017 Jiri Bilek. All right reserved. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | ------------- 21 | 22 | WiFi SPI Safe Master for connecting with ESP8266 23 | On ESP8266 must be flashed WiFiSPIESP application 24 | Connect the SPI Master device to the following pins on the esp8266: 25 | 26 | ESP8266 | 27 | GPIO NodeMCU Name | Uno 28 | =================================== 29 | 15 D8 SS | D10** 30 | 13 D7 MOSI | D11 31 | 12 D6 MISO | D12 32 | 14 D5 SCK | D13 33 | 34 | **) User changeable 35 | 36 | Based on Hristo Gochkov's SPISlave library. 37 | */ 38 | 39 | #ifndef _ESPSPI_PROXY_H 40 | #define _ESPSPI_PROXY_H 41 | 42 | /* clang-format off */ 43 | 44 | // The command codes are fixed by ESP8266 hardware 45 | #define CMD_WRITESTATUS 0x01 46 | #define CMD_WRITEDATA 0x02 47 | #define CMD_READDATA 0x03 48 | #define CMD_READSTATUS 0x04 49 | 50 | // Message indicators 51 | #define MESSAGE_FINISHED 0xDF 52 | #define MESSAGE_CONTINUES 0xDC 53 | 54 | // SPI Status 55 | enum 56 | { 57 | SPISLAVE_RX_BUSY, 58 | SPISLAVE_RX_READY, 59 | SPISLAVE_RX_CRC_PROCESSING, 60 | SPISLAVE_RX_ERROR 61 | }; 62 | 63 | enum 64 | { 65 | SPISLAVE_TX_NODATA, 66 | SPISLAVE_TX_READY, 67 | SPISLAVE_TX_PREPARING_DATA, 68 | SPISLAVE_TX_WAITING_FOR_CONFIRM 69 | }; 70 | 71 | // How long we will wait for slave to be ready 72 | #define SLAVE_RX_READY_TIMEOUT 3000UL 73 | #define SLAVE_TX_READY_TIMEOUT 3000UL 74 | 75 | // How long will be SS held high when starting transmission 76 | // #define SS_PULSE_DELAY_MICROSECONDS 50 77 | 78 | /* clang-format on */ 79 | 80 | void EspSpiProxy_begin(void); 81 | void EspSpiProxy_pulseSS(uint8_t start); 82 | uint16_t EspSpiProxy_readStatus(); 83 | void EspSpiProxy_writeStatus(uint8_t status); 84 | void EspSpiProxy_readData(uint8_t *buf); 85 | // void EspSpiProxy_writeData(uint8_t *data, size_t len); 86 | void EspSpiProxy_writeData(uint8_t *data); 87 | void EspSpiProxy_flush(uint8_t indicator); 88 | void EspSpiProxy_writeByte(uint8_t b); 89 | uint8_t EspSpiProxy_readByte(); 90 | int8_t EspSpiProxy_waitForSlaveRxReady(); 91 | int8_t EspSpiProxy_waitForSlaveTxReady(); 92 | void EspSpiProxy_hardReset(int8_t hwResetPin); 93 | int8_t EspSpiProxy_waitForSlaveRxConfirmation(); 94 | #endif 95 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/wifi/utility/srvspi_drv.h: -------------------------------------------------------------------------------- 1 | /* 2 | srvspi_drv.h - Library for Arduino Wifi SPI connection with ESP8266. 3 | Copyright (c) 2017 Jiri Bilek. All right reserved. 4 | 5 | --- 6 | 7 | Based on server_drv.h - Library for Arduino Wifi shield. 8 | Copyright (c) 2011-2014 Arduino. All right reserved. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _SRVSPI_DRV_H_INCLUDED 26 | #define _SRVSPI_DRV_H_INCLUDED 27 | 28 | #include 29 | #include "wifi_spi.h" 30 | #include 31 | 32 | typedef enum eProtMode 33 | { 34 | TCP_MODE, 35 | UDP_MODE, 36 | TCP_MODE_WITH_TLS 37 | } tProtMode_t; 38 | 39 | bool ServerSpiDrv_startServer(uint16_t port, uint8_t sock, uint8_t protMode); 40 | void ServerSpiDrv_stopServer(uint8_t sock); 41 | bool ServerSpiDrv_startClient(uint32_t ipAddress, uint16_t port, uint8_t sock, uint8_t protMode); 42 | void ServerSpiDrv_stopClient(uint8_t sock); 43 | uint8_t ServerSpiDrv_getServerState(uint8_t sock); 44 | uint8_t ServerSpiDrv_getClientState(const uint8_t sock); 45 | uint16_t ServerSpiDrv_availData(const uint8_t sock); 46 | bool ServerSpiDrv_getData(const uint8_t sock, int16_t *data, const uint8_t peek); 47 | bool ServerSpiDrv_getDataBuf(const uint8_t sock, uint8_t *_data, uint16_t *_dataLen); 48 | bool ServerSpiDrv_insertDataBuf(uint8_t sock, const uint8_t *data, uint16_t _len); 49 | bool ServerSpiDrv_sendUdpData(uint8_t sock); 50 | bool ServerSpiDrv_sendData(const uint8_t sock, const uint8_t *data, const uint16_t len); 51 | bool ServerSpiDrv_beginUdpPacket(uint32_t ipAddress, uint16_t port, uint8_t sock); 52 | uint16_t ServerSpiDrv_parsePacket(const uint8_t sock); 53 | uint8_t ServerSpiDrv_verifySSLClient(const uint8_t sock, uint8_t *fingerprint, const char *host); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/wifi/utility/wifispi_drv.h: -------------------------------------------------------------------------------- 1 | /* 2 | wifispi_drv.h - Library for Arduino SPI connection to ESP8266 3 | Copyright (c) 2017 Jiri Bilek. All right reserved. 4 | 5 | --- 6 | 7 | Based on: wifi_drv.h - Library for Arduino Wifi shield. 8 | Copyright (c) 2011-2014 Arduino. All right reserved. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #ifndef _WIFISPI_DRV_H_INCLUDED 26 | #define _WIFISPI_DRV_H_INCLUDED 27 | 28 | #include 29 | #include "wifi_spi.h" 30 | #include 31 | 32 | /* clang-format off */ 33 | // Key index length 34 | ///#define KEY_IDX_LEN 1 35 | // 100 ms secs of delay to test if the connection is established 36 | #define WL_DELAY_START_CONNECTION 100 37 | // Firmware version string length (format a.b.c) 38 | #define WL_FW_VER_LENGTH 6 39 | // Protocol version string length (format a.b.c) 40 | #define WL_PROTOCOL_VER_LENGTH 6 41 | 42 | #define DUMMY_DATA 0xFF 43 | /* clang-format on */ 44 | 45 | typedef struct 46 | { 47 | uint8_t address[WL_IPV4_LENGTH]; 48 | } IPAddress_t; 49 | 50 | bool WiFiSpiDrv_getRemoteData(uint8_t sock, uint8_t *ip, uint16_t *port); 51 | 52 | void WiFiSpiDrv_wifiDriverInit(void); 53 | int8_t WiFiSpiDrv_wifiSetNetwork(const char *ssid, uint8_t ssid_len); 54 | int8_t WiFiSpiDrv_wifiSetPassphrase(const char *ssid, const uint8_t ssid_len, const char *passphrase, const uint8_t len); 55 | bool WiFiSpiDrv_config(uint32_t local_ip, uint32_t gateway, uint32_t subnet, uint32_t dns_server1, uint32_t dns_server2); 56 | uint8_t WiFiSpiDrv_disconnect(); 57 | uint8_t WiFiSpiDrv_getConnectionStatus(); 58 | uint8_t *WiFiSpiDrv_getMacAddress(); 59 | int8_t WiFiSpiDrv_getIpAddress(IPAddress_t *ip); 60 | int8_t WiFiSpiDrv_getSubnetMask(IPAddress_t *mask); 61 | int8_t WiFiSpiDrv_getGatewayIP(IPAddress_t *ip); 62 | char *WiFiSpiDrv_getCurrentSSID(); 63 | uint8_t *WiFiSpiDrv_getCurrentBSSID(); 64 | int32_t WiFiSpiDrv_getCurrentRSSI(); 65 | int8_t WiFiSpiDrv_startScanNetworks(); 66 | int8_t WiFiSpiDrv_getScanNetworks(); 67 | char *WiFiSpiDrv_getSSIDNetworks(uint8_t networkItem); 68 | uint8_t WiFiSpiDrv_getEncTypeNetworks(uint8_t networkItem); 69 | int32_t WiFiSpiDrv_getRSSINetworks(uint8_t networkItem); 70 | int8_t WiFiSpiDrv_getHostByName(const char *aHostname, IPAddress_t *aResult); 71 | char *WiFiSpiDrv_getFwVersion(); 72 | void WiFiSpiDrv_softReset(void); 73 | char *WiFiSpiDrv_getProtocolVersion(); 74 | 75 | uint32_t IPAddress_to_uint32(IPAddress_t *ip); 76 | IPAddress_t uint8_to_IPAddress(uint8_t *ip); 77 | char *IPAddress_to_string(IPAddress_t *ip); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/wifi/utility/wl_definitions.h: -------------------------------------------------------------------------------- 1 | /* 2 | wl_definitions.h - Library for Arduino Wifi shield. 3 | Copyright (c) 2011-2014 Arduino. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | /* 20 | * wl_definitions.h 21 | * 22 | * Created on: Mar 6, 2011 23 | * Author: dlafauci 24 | */ 25 | 26 | #ifndef _WL_DEFINITIONS_H_INCLUDED 27 | #define _WL_DEFINITIONS_H_INCLUDED 28 | 29 | /* clang-format off */ 30 | 31 | // Maximum size of a SSID 32 | #define WL_SSID_MAX_LENGTH 32 33 | // Length of passphrase. Valid lengths are 8-63. 34 | #define WL_WPA_KEY_MAX_LENGTH 63 35 | // Length of key in bytes. Valid values are 5 and 13. 36 | #define WL_WEP_KEY_MAX_LENGTH 13 37 | // Size of a MAC-address or BSSID 38 | #define WL_MAC_ADDR_LENGTH 6 39 | // Size of a MAC-address or BSSID 40 | #define WL_IPV4_LENGTH 4 41 | // Maximum size of a SSID list 42 | #define WL_NETWORKS_LIST_MAXNUM 10 43 | // Maxmium number of socket 44 | #define MAX_SOCK_NUM 4 45 | // Socket not available constant 46 | #define SOCK_NOT_AVAIL 255 47 | // Default state value for Wifi state field 48 | #define NA_STATE -1 49 | // Maximum waiting time to establish wifi connection is 10 s (in WL_DELAY_START_CONNECTION = 100 ms) 50 | #define WL_MAX_ATTEMPT_CONNECTION 100 51 | 52 | /* clang-format on */ 53 | 54 | typedef enum 55 | { 56 | WL_NO_SHIELD = 255, 57 | WL_IDLE_STATUS = 0, 58 | WL_NO_SSID_AVAIL, 59 | WL_SCAN_COMPLETED, 60 | WL_CONNECTED, 61 | WL_CONNECT_FAILED, 62 | WL_CONNECTION_LOST, 63 | WL_DISCONNECTED 64 | } wl_status_t; 65 | 66 | /* Encryption modes */ 67 | /*enum wl_enc_type { // Values map to 802.11 encryption suites... 68 | ENC_TYPE_WEP = 5, 69 | ENC_TYPE_TKIP = 2, 70 | ENC_TYPE_CCMP = 4, 71 | // ... except these two, 7 and 8 are reserved in 802.11-2007 72 | ENC_TYPE_NONE = 7, 73 | ENC_TYPE_AUTO = 8 74 | };*/ 75 | 76 | #endif /* WL_DEFINITIONS_H_ */ 77 | -------------------------------------------------------------------------------- /projects/MF1/main/network/esp8285/wifi/utility/wl_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | wl_types.h - Library for Arduino Wifi shield. 3 | Copyright (c) 2011-2014 Arduino. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | /* 20 | * wl_types.h 21 | * 22 | * Created on: Jul 30, 2010 23 | * Author: dlafauci 24 | */ 25 | 26 | #ifndef _WL_TYPES_H_INCLUDED 27 | #define _WL_TYPES_H_INCLUDED 28 | 29 | #include 30 | 31 | typedef enum 32 | { 33 | WL_FAILURE = -1, 34 | WL_SUCCESS = 1, 35 | } wl_error_code_t; 36 | 37 | /* Authentication modes */ 38 | enum wl_auth_mode 39 | { 40 | AUTH_MODE_INVALID, 41 | AUTH_MODE_AUTO, 42 | AUTH_MODE_OPEN_SYSTEM, 43 | AUTH_MODE_SHARED_KEY, 44 | AUTH_MODE_WPA, 45 | AUTH_MODE_WPA2, 46 | AUTH_MODE_WPA_PSK, 47 | AUTH_MODE_WPA2_PSK 48 | }; 49 | 50 | #endif //_WL_TYPES_H_ 51 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/arduino_lib.txt: -------------------------------------------------------------------------------- 1 | https://github.com/arduino-libraries/Ethernet.git 2 | commit id: 4f4ac17f296f5ffbe869730db88265ddc3e4fc15 -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/demo_w5500.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEMO_W5500_H 2 | #define __DEMO_W5500_H 3 | 4 | #include "global_config.h" 5 | 6 | #if CONFIG_NET_ENABLE 7 | #if CONFIG_NET_W5500 8 | 9 | /* clang-format off */ 10 | 11 | /*speed test, get 150K */ 12 | #define HTTP_GET_URL "http://119.145.88.166:8080/download?nocache=ab86f05e-1195-43a6-8685-8c78f2a70ecf&size=102400" 13 | 14 | #define HTTP_GET_DEMO (1) 15 | #define HTTP_POST_DEMO (1) 16 | 17 | #define MQTT_DEMO (1) 18 | 19 | #define HTTPD_DEMO (1) 20 | 21 | /* clang-format on */ 22 | 23 | #endif 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/httpc/http_file.h: -------------------------------------------------------------------------------- 1 | #ifndef __HTTP_GET_FILE_H 2 | #define __HTTP_GET_FILE_H 3 | 4 | uint32_t http_get_file(char *url, 5 | char *custom_headers, 6 | char *resp_header, 7 | uint32_t resp_header_len, 8 | uint8_t *file, 9 | uint32_t file_len); 10 | 11 | uint32_t http_post_file(char *url, 12 | char *custom_headers, 13 | uint8_t *body, 14 | uint8_t *boundary, 15 | uint8_t *post_file, 16 | uint32_t post_file_len, 17 | char *resp_header, 18 | uint32_t resp_header_len, 19 | uint8_t *file, 20 | uint32_t file_len); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/httpc/http_save_file.h: -------------------------------------------------------------------------------- 1 | #ifndef __HTTP_SAVE_FILE_H 2 | #define __HTTP_SAVE_FILE_H 3 | 4 | uint32_t http_save_file(eth_tcp_client_t *client, 5 | char *resp_header, uint32_t resp_header_len, 6 | uint8_t *file, uint32_t file_len); 7 | #endif -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/httpc/http_simple.h: -------------------------------------------------------------------------------- 1 | // #ifndef __HTTP_SIMPLE_H 2 | // #define __HTTP_SIMPLE_H 3 | 4 | // /* 5 | // Represents an HTTP html response 6 | // */ 7 | // struct http_response 8 | // { 9 | // struct parsed_url *request_uri; 10 | // char *body; 11 | // uint32_t body_len; 12 | // char *status_code; 13 | // int status_code_int; 14 | // char *status_text; 15 | // char *request_headers; 16 | // char *response_headers; 17 | // }; 18 | 19 | // struct http_response *http_get(char *url, char *custom_headers); 20 | // struct http_response *http_post(char *url, char *custom_headers, char *post_data); 21 | 22 | // void http_response_free(struct http_response *hresp); 23 | 24 | // #endif -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/httpc/my_str.h: -------------------------------------------------------------------------------- 1 | #ifndef __MY_STR_H 2 | #define __MY_STR_H 3 | 4 | // int my_atoi(char *string); 5 | 6 | int my_isalpha(int ch); 7 | char my_isdigit(unsigned char c); 8 | int my_isalnum(int c); 9 | int my_str_index_of(const char *a, char *b); 10 | int my_str_contains(const char *haystack, const char *needle); 11 | char *my_trim_end(char *string, char to_trim); 12 | char *my_str_cat(char *a, char *b); 13 | char my_to_hex(char code); 14 | char *my_urlencode(char *str); 15 | char *my_str_ndup(const char *str, size_t max); 16 | char *my_str_dup(const char *src); 17 | char *my_str_replace(char *search, char *replace, char *subject); 18 | char *my_get_until(char *haystack, char *until); 19 | void my_decodeblock(unsigned char in[], char *clrstr); 20 | char *my_base64_decode(char *b64src); 21 | void my_encodeblock(unsigned char in[], char b64str[], int len); 22 | char *my_base64_encode(char *clrstr); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/httpc/parsed_url.h: -------------------------------------------------------------------------------- 1 | #ifndef __PARSED_URL_H 2 | #define __PARSED_URL_H 3 | 4 | #define NOT_ONLY_SUPPORT_GET 0 5 | 6 | struct parsed_url 7 | { 8 | char *uri; /* mandatory */ 9 | char *scheme; /* mandatory */ 10 | char *host; /* mandatory */ 11 | char *ip; /* mandatory */ 12 | char *port; /* optional */ 13 | char *path; /* optional */ 14 | char *query; /* optional */ 15 | #if NOT_ONLY_SUPPORT_GET 16 | char *fragment; /* optional */ 17 | char *username; /* optional */ 18 | char *password; /* optional */ 19 | #endif 20 | }; 21 | 22 | void parsed_url_free(struct parsed_url *purl); 23 | struct parsed_url *parse_url(const char *url); 24 | 25 | #endif -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/httpd/src/httpd.h: -------------------------------------------------------------------------------- 1 | #ifndef __HTTPD_H 2 | #define __HTTPD_H 3 | 4 | #include 5 | 6 | #include "EthernetClient.h" 7 | 8 | /////////////////////////////////////////////////////////////////////////////// 9 | /* clang-format off */ 10 | #ifndef MIN 11 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) 12 | #endif 13 | 14 | #define SERVER_SOFTWARE "mini_httpd/1.30 26Oct2018" 15 | #define SERVER_URL "http://www.acme.com/software/mini_httpd/" 16 | #define CHAERSET "utf-8" 17 | 18 | #define ENABLE_AUTH (0) 19 | #define AUTH_USER "admin" 20 | #define AUTH_PASSWD "123456" 21 | 22 | #define METHOD_UNKNOWN (0) 23 | #define METHOD_GET (1) 24 | #define METHOD_HEAD (2) 25 | #define METHOD_POST (3) 26 | #define METHOD_PUT (4) 27 | #define METHOD_DELETE (5) 28 | #define METHOD_TRACE (6) 29 | 30 | #define HTTP_REQUEST_OK (200) 31 | #define HTTP_BAD_REQUEST (400) 32 | #define HTTP_UNAUTHORIZED (401) 33 | #define HTTP_FORBIDDEN (403) 34 | #define HTTP_NOT_FOUND (404) 35 | #define HTTP_METHOD_NA (405) 36 | #define HTTP_ERROR (500) 37 | #define HTTP_NOT_IMPLEMENT (501) 38 | 39 | /* clang-format on */ 40 | /////////////////////////////////////////////////////////////////////////////// 41 | typedef struct _httpd_post_data httpd_post_data_t; 42 | typedef struct _httpd_post_data 43 | { 44 | int size; //should be more big than len 45 | //otherwise will realloc failed 46 | int len; 47 | char *buf; 48 | struct httpd_post_data_t *next; 49 | } httpd_post_data_t; 50 | 51 | typedef struct _httpd_req 52 | { 53 | /* Request variables. */ 54 | eth_tcp_client_t *client; 55 | 56 | char *request; 57 | size_t request_size, request_len, request_idx; 58 | int method; 59 | char *path; 60 | char *file; 61 | char *pathinfo; 62 | char *query; 63 | char *protocol; 64 | int status; 65 | long bytes; 66 | char *req_hostname; 67 | char *authorization; 68 | size_t content_length; 69 | char *content_type; 70 | char *cookie; 71 | char *host; 72 | time_t if_modified_since; 73 | char *referrer; 74 | char *useragent; 75 | char *remoteuser; 76 | 77 | char *response; 78 | size_t response_size, response_len; 79 | 80 | httpd_post_data_t *post_data; 81 | 82 | } httpd_req_t; 83 | 84 | void httpd_handle_request(eth_tcp_client_t *client); 85 | 86 | int httpd_read(httpd_req_t *req, char *buf, int len); 87 | int httpd_write(httpd_req_t *req, char *buf, int len); 88 | 89 | /////////////////////////////////////////////////////////////////////////////// 90 | /* httpd_util.c */ 91 | void add_data(char **bufP, size_t *bufsizeP, size_t *buflenP, char *str, size_t len); 92 | void add_str(char **bufP, size_t *bufsizeP, size_t *buflenP, char *str); 93 | 94 | void strdecode(char *to, char *from); 95 | void de_dotdot(char *f); 96 | 97 | int b64_decode(const char *str, unsigned char *space, int size); 98 | 99 | /////////////////////////////////////////////////////////////////////////////// 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/httpd/src/match.c: -------------------------------------------------------------------------------- 1 | /* match.c - simple shell-style filename matcher 2 | ** 3 | ** Only does ? * and **, and multiple patterns separated by |. Returns 1 or 0. 4 | ** 5 | ** Copyright � 1995,2000 by Jef Poskanzer . 6 | ** All rights reserved. 7 | ** 8 | ** Redistribution and use in source and binary forms, with or without 9 | ** modification, are permitted provided that the following conditions 10 | ** are met: 11 | ** 1. Redistributions of source code must retain the above copyright 12 | ** notice, this list of conditions and the following disclaimer. 13 | ** 2. Redistributions in binary form must reproduce the above copyright 14 | ** notice, this list of conditions and the following disclaimer in the 15 | ** documentation and/or other materials provided with the distribution. 16 | ** 17 | ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | ** SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | 32 | #include "match.h" 33 | 34 | static int match_one(const char *pattern, int patternlen, const char *string); 35 | 36 | int match(const char *pattern, const char *string) 37 | { 38 | const char * or ; 39 | 40 | for (;;) 41 | { 42 | or = strchr(pattern, '|'); 43 | if (or == (char *)0) 44 | return match_one(pattern, strlen(pattern), string); 45 | if (match_one(pattern, or -pattern, string)) 46 | return 1; 47 | pattern = or +1; 48 | } 49 | } 50 | 51 | static int match_one(const char *pattern, int patternlen, const char *string) 52 | { 53 | const char *p; 54 | 55 | for (p = pattern; p - pattern < patternlen; ++p, ++string) 56 | { 57 | if (*p == '?' && *string != '\0') 58 | continue; 59 | if (*p == '*') 60 | { 61 | int i, pl; 62 | ++p; 63 | if (*p == '*') 64 | { 65 | /* Double-wildcard matches anything. */ 66 | ++p; 67 | i = strlen(string); 68 | } 69 | else 70 | /* Single-wildcard matches anything but slash. */ 71 | i = strcspn(string, "/"); 72 | pl = patternlen - (p - pattern); 73 | for (; i >= 0; --i) 74 | if (match_one(p, pl, &(string[i]))) 75 | return 1; 76 | return 0; 77 | } 78 | if (*p != *string) 79 | return 0; 80 | } 81 | if (*string == '\0') 82 | return 1; 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/httpd/src/match.h: -------------------------------------------------------------------------------- 1 | /* match.h - simple shell-style filename patcher 2 | ** 3 | ** Copyright � 1995 by Jef Poskanzer . 4 | ** All rights reserved. 5 | ** 6 | ** Redistribution and use in source and binary forms, with or without 7 | ** modification, are permitted provided that the following conditions 8 | ** are met: 9 | ** 1. Redistributions of source code must retain the above copyright 10 | ** notice, this list of conditions and the following disclaimer. 11 | ** 2. Redistributions in binary form must reproduce the above copyright 12 | ** notice, this list of conditions and the following disclaimer in the 13 | ** documentation and/or other materials provided with the distribution. 14 | ** 15 | ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 | ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 | ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 | ** SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _MATCH_H_ 29 | #define _MATCH_H_ 30 | 31 | /* Simple shell-style filename pattern matcher. Only does ? * and **, and 32 | ** multiple patterns separated by |. Returns 1 or 0. 33 | */ 34 | int match(const char *pattern, const char *string); 35 | 36 | #endif /* _MATCH_H_ */ 37 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/httpd/src/mini_httpd-1.30.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/projects/MF1/main/network/w5500/httpd/src/mini_httpd-1.30.tar.gz -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/httpd/src/tdate_parse.h: -------------------------------------------------------------------------------- 1 | /* tdate_parse.h - parse string dates into internal form, stripped-down version 2 | ** 3 | ** Copyright � 1995 by Jef Poskanzer . 4 | ** All rights reserved. 5 | ** 6 | ** Redistribution and use in source and binary forms, with or without 7 | ** modification, are permitted provided that the following conditions 8 | ** are met: 9 | ** 1. Redistributions of source code must retain the above copyright 10 | ** notice, this list of conditions and the following disclaimer. 11 | ** 2. Redistributions in binary form must reproduce the above copyright 12 | ** notice, this list of conditions and the following disclaimer in the 13 | ** documentation and/or other materials provided with the distribution. 14 | ** 15 | ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 | ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 | ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 | ** SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _TDATE_PARSE_H_ 29 | #define _TDATE_PARSE_H_ 30 | 31 | #include 32 | 33 | time_t tdate_parse(char *str); 34 | 35 | #endif /* _TDATE_PARSE_H_ */ 36 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/httpd/web_pages/web_config.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef WEB_CONFIG_H 3 | #define WEB_CONFIG_H 4 | 5 | /* specify default page */ 6 | static char config_default_page[] = "index.html"; 7 | 8 | typedef struct _err_html 9 | { 10 | int err_code; 11 | char *fname; 12 | } err_html_t; 13 | 14 | static err_html_t err_pages[] = { 15 | // {404, "404.html"}, 16 | // {500, "500.html"}, 17 | {0, NULL}, 18 | }; 19 | 20 | #endif //WEB_CONFIG_H 21 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/httpd/web_pages/webpage.h: -------------------------------------------------------------------------------- 1 | #ifndef __WEB_PAGE_H 2 | #define __WEB_PAGE_H 3 | 4 | #include "httpd.h" 5 | 6 | /////////////////////////////////////////////////////////////////////////////// 7 | typedef struct _web_html 8 | { 9 | char *url_path; 10 | 11 | uint8_t *addr; 12 | uint32_t size; 13 | 14 | uint32_t flag; 15 | } web_html_t; 16 | 17 | typedef struct _web_cmd 18 | { 19 | char *cmd_path; 20 | uint8_t (*func)(httpd_req_t *req); 21 | uint8_t method; 22 | } web_cmd_t; 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | extern time_t time_pages_created; 26 | 27 | extern web_html_t web_htmlfile_table[]; 28 | extern web_cmd_t web_cmd_table[]; 29 | 30 | /////////////////////////////////////////////////////////////////////////////// 31 | void webpage_init_size(void); 32 | 33 | /////////////////////////////////////////////////////////////////////////////// 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/spi/myspi.h: -------------------------------------------------------------------------------- 1 | #ifndef __MYSPI_H 2 | #define __MYSPI_H 3 | 4 | #include 5 | 6 | // extern volatile uint8_t w5500_irq_flag; 7 | 8 | void eth_w5500_spi_init(void); 9 | void eth_w5500_reset(uint8_t val); 10 | 11 | //lib call 12 | void eth_w5500_spi_cs_sel(void); 13 | void eth_w5500_spi_cs_desel(void); 14 | 15 | void eth_w5500_spi_write(uint8_t *send, size_t len); 16 | void eth_w5500_spi_read(uint8_t *recv, size_t len); 17 | #endif 18 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/src/Dns.h: -------------------------------------------------------------------------------- 1 | // Arduino DNS client for WizNet5100-based Ethernet shield 2 | // (c) Copyright 2009-2010 MCQN Ltd. 3 | // Released under Apache License, version 2.0 4 | 5 | #ifndef DNSClient_h 6 | #define DNSClient_h 7 | 8 | #include "utility/w5100.h" 9 | 10 | void eth_dns_begin(const IPAddress *DNSServer); 11 | int eth_dns_inet_aton(const char *address, IPAddress *result); 12 | int eth_dns_getHostByName(const char *Hostname, IPAddress *Result, uint16_t timeout); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/src/Ethernet.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Paul Stoffregen 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | * software and associated documentation files (the "Software"), to deal in the Software 5 | * without restriction, including without limitation the rights to use, copy, modify, 6 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | * permit persons to whom the Software is furnished to do so, subject to the following 8 | * conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in all 11 | * copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #ifndef __ETHERNET_H 22 | #define __ETHERNET_H 23 | 24 | #include "utility/w5100.h" 25 | 26 | enum EthernetLinkStatus 27 | { 28 | Unknown, 29 | LinkON, 30 | LinkOFF 31 | }; 32 | 33 | enum EthernetHardwareStatus 34 | { 35 | EthernetNoHardware, 36 | EthernetW5100, 37 | EthernetW5200, 38 | EthernetW5500 39 | }; 40 | 41 | int eth_w5100_begin_dhcp(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout); 42 | 43 | void eth_w5100_begin0(uint8_t *mac, IPAddress ip); 44 | void eth_w5100_begin1(uint8_t *mac, IPAddress ip, IPAddress dns); 45 | void eth_w5100_begin2(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway); 46 | 47 | void eth_w5100_begin3(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet); 48 | 49 | enum EthernetLinkStatus eth_w5100_linkStatus(); 50 | enum EthernetHardwareStatus eth_w5100_hardwareStatus(); 51 | int eth_w5100_maintain(); 52 | void eth_w5100_MACAddress(uint8_t *mac_address); 53 | IPAddress eth_w5100_localIP(); 54 | IPAddress eth_w5100_subnetMask(); 55 | IPAddress eth_w5100_gatewayIP(); 56 | IPAddress eth_w5100_dnsServerIP(); 57 | void eth_w5100_setMACAddress(const uint8_t *mac_address); 58 | void eth_w5100_setLocalIP(const IPAddress local_ip); 59 | void eth_w5100_setSubnetMask(const IPAddress subnet); 60 | void eth_w5100_setGatewayIP(const IPAddress gateway); 61 | void eth_w5100_setRetransmissionTimeout(uint16_t milliseconds); 62 | void eth_w5100_setRetransmissionCount(uint8_t num); 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/src/EthernetClient.h: -------------------------------------------------------------------------------- 1 | #ifndef __ETHERNETCLIENT_H 2 | #define __ETHERNETCLIENT_H 3 | 4 | #include "utility/w5100.h" 5 | 6 | #define TCP_CLIENT_DEFAULT_TIMEOUT 10000 7 | 8 | typedef struct _eth_tcp_client eth_tcp_client_t; 9 | 10 | typedef struct _eth_tcp_client 11 | { 12 | uint8_t sockindex; // MAX_SOCK_NUM means client not in use 13 | uint16_t _timeout; //default 10000 14 | 15 | int (*connect_domain)(eth_tcp_client_t *client, const char *host, uint16_t port); 16 | int (*connect_ip)(eth_tcp_client_t *client, IPAddress ip, uint16_t port); 17 | 18 | int (*availableForWrite)(eth_tcp_client_t *client); 19 | size_t (*write)(eth_tcp_client_t *client, const uint8_t *buf, size_t size); 20 | size_t (*write_fix)(eth_tcp_client_t *client, const uint8_t *buf, size_t size, uint16_t max_wait_ms); 21 | 22 | int (*available)(eth_tcp_client_t *client); 23 | int (*read_one)(eth_tcp_client_t *client); 24 | int (*read)(eth_tcp_client_t *client, uint8_t *buf, size_t size); 25 | 26 | int (*peek)(eth_tcp_client_t *client); 27 | void (*flush)(eth_tcp_client_t *client); 28 | void (*stop)(eth_tcp_client_t *client); 29 | 30 | uint8_t (*connected)(eth_tcp_client_t *client); 31 | uint8_t (*status)(eth_tcp_client_t *client); 32 | 33 | uint16_t (*localPort)(eth_tcp_client_t *client); 34 | IPAddress (*remoteIP)(eth_tcp_client_t *client); 35 | uint16_t (*remotePort)(eth_tcp_client_t *client); 36 | 37 | void (*destory)(eth_tcp_client_t *client); 38 | } eth_tcp_client_t; 39 | 40 | eth_tcp_client_t *eth_tcp_client_new(uint8_t sock, uint16_t timeout); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/src/EthernetServer.h: -------------------------------------------------------------------------------- 1 | #ifndef __ETHERNETSERVER_H 2 | #define __ETHERNETSERVER_H 3 | 4 | #include "utility/w5100.h" 5 | 6 | #include "EthernetClient.h" 7 | 8 | typedef struct _eth_tcp_server eth_tcp_server_t; 9 | 10 | typedef struct _eth_tcp_server 11 | { 12 | uint16_t port; 13 | 14 | void (*begin)(eth_tcp_server_t *server); 15 | eth_tcp_client_t *(*available)(eth_tcp_server_t *server); 16 | 17 | eth_tcp_client_t *(*accept)(eth_tcp_server_t *server); 18 | size_t (*write)(eth_tcp_server_t *server, uint8_t *buffer, size_t size); 19 | 20 | void (*destory)(eth_tcp_server_t *server); 21 | 22 | } eth_tcp_server_t; 23 | 24 | eth_tcp_server_t *eth_tcp_server_new(uint16_t port); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/src/EthernetUdp.h: -------------------------------------------------------------------------------- 1 | #ifndef __ETHERNET_UDP_H 2 | #define __ETHERNET_UDP_H 3 | 4 | #include "utility/w5100.h" 5 | 6 | #define UDP_TX_PACKET_MAX_SIZE 24 7 | 8 | typedef struct _eth_udp eth_udp_t; 9 | 10 | typedef struct _eth_udp 11 | { 12 | uint16_t _port; // local port to listen on 13 | IPAddress _remoteIP; // remote IP address for the incoming packet whilst it's being processed 14 | uint16_t _remotePort; // remote port for the incoming packet whilst it's being processed 15 | uint16_t _offset; // offset into the packet being sent 16 | 17 | uint8_t sockindex; 18 | uint16_t _remaining; // remaining bytes of incoming packet yet to be processed 19 | 20 | uint8_t (*begin)(eth_udp_t *udp, uint16_t port); 21 | int (*available)(eth_udp_t *udp); 22 | void (*stop)(eth_udp_t *udp); 23 | int (*beginPacket_domain)(eth_udp_t *udp, const char *host, uint16_t port); 24 | int (*beginPacket_ip)(eth_udp_t *udp, IPAddress ip, uint16_t port); 25 | int (*endPacket)(eth_udp_t *udp); 26 | size_t (*write)(eth_udp_t *udp, const uint8_t *buffer, size_t size); 27 | int (*parsePacket)(eth_udp_t *udp); 28 | int (*read_one)(eth_udp_t *udp); 29 | int (*read)(eth_udp_t *udp, unsigned char *buffer, size_t len); 30 | int (*peek)(eth_udp_t *udp); 31 | void (*flush)(eth_udp_t *udp); 32 | uint8_t (*beginMulticast)(eth_udp_t *udp, IPAddress ip, uint16_t port); 33 | uint16_t (*remote_port)(eth_udp_t *udp); 34 | void (*remote_ip)(eth_udp_t *udp, IPAddress *ip); 35 | 36 | void (*destory)(eth_udp_t *udp); 37 | } eth_udp_t; 38 | 39 | eth_udp_t *eth_udp_new(void); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/src/utility/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef __SOCKET_H 2 | #define __SOCKET_H 3 | 4 | #include "utility/w5100.h" 5 | 6 | extern uint16_t eth_server_port[MAX_SOCK_NUM]; 7 | 8 | void W5100_socketPortRand(uint16_t n); 9 | uint8_t W5100_socketBegin(uint8_t protocol, uint16_t port); 10 | uint8_t W5100_socketBeginMulticast(uint8_t protocol, IPAddress ip, uint16_t port); 11 | void W5100_socketClose(uint8_t s); 12 | uint8_t W5100_socketListen(uint8_t s); 13 | void W5100_socketConnect(uint8_t s, uint8_t *addr, uint16_t port); 14 | void W5100_socketDisconnect(uint8_t s); 15 | int W5100_socketRecv(uint8_t s, uint8_t *buf, int16_t len); 16 | uint16_t W5100_socketRecvAvailable(uint8_t s); 17 | uint8_t W5100_socketPeek(uint8_t s); 18 | uint16_t W5100_socketSend(uint8_t s, const uint8_t *buf, uint16_t len); 19 | uint16_t W5100_socketSendAvailable(uint8_t s); 20 | uint16_t W5100_socketBufferData(uint8_t s, uint16_t offset, const uint8_t *buf, uint16_t len); 21 | bool W5100_socketStartUDP(uint8_t s, uint8_t *addr, uint16_t port); 22 | bool W5100_socketSendUDP(uint8_t s); 23 | 24 | uint8_t W5100_socketStatus(uint8_t s); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /projects/MF1/main/network/w5500/src/utility/util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H 2 | #define UTIL_H 3 | 4 | #define htons(x) ((((x) << 8) & 0xFF00) | (((x) >> 8) & 0xFF)) 5 | #define ntohs(x) htons(x) 6 | 7 | #define htonl(x) (((x) << 24 & 0xFF000000UL) | \ 8 | ((x) << 8 & 0x00FF0000UL) | \ 9 | ((x) >> 8 & 0x0000FF00UL) | \ 10 | ((x) >> 24 & 0x000000FFUL)) 11 | #define ntohl(x) htonl(x) 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /projects/MF1/main/sd_op/include/sd_op.h: -------------------------------------------------------------------------------- 1 | #ifndef __SD_OP_H 2 | #define __SD_OP_H 3 | 4 | #include 5 | 6 | #include "ff.h" 7 | 8 | #include "face_lib.h" 9 | 10 | #include "face_cb.h" 11 | 12 | extern FATFS fs; 13 | 14 | uint8_t sd_init_fatfs(void); 15 | 16 | uint8_t sd_save_img_ppm(char *fname, image_t *img, uint8_t r8g8b8); 17 | 18 | uint8_t sd_chk_ota_file_available(char *path); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /projects/MF1/main/uart_recv/uart_recv.h: -------------------------------------------------------------------------------- 1 | #ifndef __UART_RECV_H 2 | #define __UART_RECV_H 3 | 4 | #include "flash.h" 5 | #include "face_lib.h" 6 | 7 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 8 | 9 | extern volatile uint8_t recv_over_flag; 10 | extern volatile uint8_t jpeg_recv_start_flag; 11 | 12 | extern uint32_t jpeg_recv_len; 13 | extern uint64_t jpeg_recv_start_time; 14 | 15 | extern uint8_t cJSON_prase_buf[PROTOCOL_BUF_LEN]; 16 | extern uint8_t jpeg_recv_buf[JPEG_BUF_LEN]; 17 | 18 | extern pkt_head_t g_pkt_head; 19 | 20 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 21 | int8_t protocol_init_device(board_cfg_t *brd_cfg, uint8_t op); 22 | 23 | void protocol_start_recv_jpeg(void); 24 | void protocol_stop_recv_jpeg(void); 25 | 26 | void init_relay_key_pin(board_cfg_t *brd_cfg); 27 | void init_lcd_cam(board_cfg_t *brd_cfg); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /projects/MF1/main/ui/pic/0.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/projects/MF1/main/ui/pic/0.bmp -------------------------------------------------------------------------------- /projects/MF1/main/ui/pic/1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/projects/MF1/main/ui/pic/1.bmp -------------------------------------------------------------------------------- /projects/MF1/main/ui/pic/2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/projects/MF1/main/ui/pic/2.bmp -------------------------------------------------------------------------------- /projects/MF1/main/ui/pic/3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/projects/MF1/main/ui/pic/3.bmp -------------------------------------------------------------------------------- /projects/MF1/main/ui/pic/4.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/projects/MF1/main/ui/pic/4.bmp -------------------------------------------------------------------------------- /projects/MF1/main/ui/pic/5.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/projects/MF1/main/ui/pic/5.bmp -------------------------------------------------------------------------------- /projects/MF1/main/ui/pic/6.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/projects/MF1/main/ui/pic/6.bmp -------------------------------------------------------------------------------- /projects/MF1/main/ui/pic/flash-list.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.0", 3 | "files": [ 4 | { 5 | "address": 12582912, 6 | "bin": "0.bin", 7 | "sha256Prefix": false 8 | }, 9 | { 10 | "address": 12701696, 11 | "bin": "1.bin", 12 | "sha256Prefix": false 13 | }, 14 | { 15 | "address": 12820480, 16 | "bin": "2.bin", 17 | "sha256Prefix": false 18 | }, 19 | { 20 | "address": 12939264, 21 | "bin": "3.bin", 22 | "sha256Prefix": false 23 | }, 24 | { 25 | "address": 13058048, 26 | "bin": "4.bin", 27 | "sha256Prefix": false 28 | }, 29 | { 30 | "address": 13176832, 31 | "bin": "5.bin", 32 | "sha256Prefix": false 33 | }, 34 | { 35 | "address": 13295616, 36 | "bin": "6.bin", 37 | "sha256Prefix": false 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /projects/MF1/main/ui/pic/gen_imgbin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | merge="_unmerge" 4 | flash= 5 | 6 | function ergodic(){ 7 | for file in ` ls $1` 8 | do 9 | if [ -d $1"/"$file ] 10 | then 11 | ergodic $1"/"$file 12 | else 13 | local path=$1"/"$file #得到文件的完整的目录 14 | local name=$file #得到文件的名字 15 | #做自己的工作. 16 | if [ "${file##*.}" = "bmp" ]; then 17 | if [ "$2" -eq "1" ] ; then 18 | flash="_quad" 19 | python3 bmp2hex.py $file -kbin -be 20 | else 21 | flash="_std" 22 | python3 bmp2hex.py $file -kbin 23 | fi 24 | fi 25 | fi 26 | done 27 | } 28 | 29 | INIT_PATH="." 30 | ergodic $INIT_PATH $1 31 | 32 | #delete exist file 33 | if [ -e pic.kfpkg ] 34 | then 35 | rm pic.kfpkg 36 | fi 37 | 38 | #compress bin to kfpkg 39 | zip pic$merge$flash.kfpkg flash-list.json 1.bin 2.bin 3.bin 4.bin 5.bin \ 40 | 6.bin 41 | 42 | if [ "$2" -eq "1" ] ;then 43 | echo "merge kfpkg" 44 | 45 | #merge kfpkg to bin 46 | python3 merge_kfpkg.py pic$merge$flash.kfpkg 47 | rm pic$merge$flash.kfpkg 48 | # addr file save_file 49 | python3 pack_kfpkg.py 12582912 pic$merge$flash.bin pic_merge$flash.kfpkg 50 | fi 51 | 52 | rm *.bin 53 | -------------------------------------------------------------------------------- /projects/MF1/main/ui/pic/pack_kfpkg.py: -------------------------------------------------------------------------------- 1 | import sys,os,json,zipfile,tempfile 2 | 3 | class KFPKG(): 4 | def __init__(self): 5 | self.fileInfo = {"version": "0.1.0", "files": []} 6 | self.filePath = {} 7 | self.burnAddr = [] 8 | 9 | def addFile(self, addr, path, prefix=False): 10 | if not os.path.exists(path): 11 | raise ValueError(("FilePathError")) 12 | if addr in self.burnAddr: 13 | raise ValueError(("Burn dddr duplicate")+":0x%06x" %(addr)) 14 | f = {} 15 | f_name = os.path.split(path)[1] 16 | f["address"] = int(addr) 17 | f["bin"] = f_name 18 | f["sha256Prefix"] = prefix 19 | self.fileInfo["files"].append(f) 20 | self.filePath[f_name] = path 21 | self.burnAddr.append(addr) 22 | 23 | def listDumps(self): 24 | kfpkg_json = json.dumps(self.fileInfo, indent=4) 25 | return kfpkg_json 26 | 27 | def listDump(self, path): 28 | with open(path, "w") as f: 29 | f.write(json.dumps(self.fileInfo, indent=4)) 30 | 31 | def listLoads(self, kfpkgJson): 32 | self.fileInfo = json.loads(kfpkgJson) 33 | 34 | def listLload(self, path): 35 | with open(path) as f: 36 | self.fileInfo = json.load(f) 37 | 38 | def save(self, path): 39 | listName = os.path.join(tempfile.gettempdir(), "kflash_gui_tmp_list.json") 40 | self.listDump(listName) 41 | try: 42 | with zipfile.ZipFile(path, "w") as zip: 43 | for name,path in self.filePath.items(): 44 | zip.write(path, arcname=name, compress_type=zipfile.ZIP_DEFLATED) 45 | zip.write(listName, arcname="flash-list.json", compress_type=zipfile.ZIP_DEFLATED) 46 | zip.close() 47 | except Exception as e: 48 | os.remove(listName) 49 | raise e 50 | os.remove(listName) 51 | 52 | kfpkg = KFPKG() 53 | kfpkg.addFile(sys.argv[1],sys.argv[2]) 54 | kfpkg.save(sys.argv[3]) 55 | -------------------------------------------------------------------------------- /projects/MF1/main/ui/pic/pic_merge_quad.kfpkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipeed/MF1_SDK/HEAD/projects/MF1/main/ui/pic/pic_merge_quad.kfpkg -------------------------------------------------------------------------------- /projects/MF1/project.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #-*- coding = utf-8 -*- 3 | 4 | # 5 | # @file from https://github.com/Neutree/c_cpp_project_framework 6 | # @author neucrack 7 | # @license Apache 2.0 8 | # 9 | 10 | import sys, os 11 | 12 | sdk_env_name = "MY_SDK_PATH" 13 | 14 | # get SDK absolute path 15 | sdk_path = os.path.abspath(sys.path[0]+"/../../") 16 | try: 17 | sdk_path = os.environ[sdk_env_name] 18 | except Exception: 19 | pass 20 | print("-- SDK_PATH:{}".format(sdk_path)) 21 | 22 | # execute project script from SDK 23 | project_file_path = sdk_path+"/tools/cmake/project.py" 24 | with open(project_file_path) as f: 25 | exec(f.read()) 26 | 27 | -------------------------------------------------------------------------------- /projects/hello_world/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | 3 | build 4 | .config.mk 5 | .flash.conf.json 6 | 7 | -------------------------------------------------------------------------------- /projects/hello_world/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9) 2 | 3 | 4 | # Get SDK path 5 | if(NOT SDK_PATH) 6 | get_filename_component(SDK_PATH ../../ ABSOLUTE) 7 | if(EXISTS $ENV{MY_SDK_PATH}) 8 | set(SDK_PATH $ENV{MY_SDK_PATH}) 9 | endif() 10 | endif() 11 | 12 | # Check SDK Path 13 | if(NOT EXISTS ${SDK_PATH}) 14 | message(FATAL_ERROR "SDK path Error, Please set SDK_PATH or MY_SDK_PATH variable") 15 | endif() 16 | 17 | # Get Toolchain path 18 | if(NOT CONFIG_TOOLCHAIN_PATH) 19 | if(EXISTS $ENV{MY_TOOLCHAIN_PATH}) 20 | set(CONFIG_TOOLCHAIN_PATH $ENV{MY_TOOLCHAIN_PATH}) 21 | endif() 22 | endif() 23 | 24 | ## Add preprocessor definitions for whole project 25 | # add_definitions(-DAAAAA=1) 26 | 27 | # Call compile 28 | include(${SDK_PATH}/tools/cmake/compile.cmake) 29 | 30 | 31 | # Project Name 32 | project(hello_world) 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /projects/hello_world/compile/gen_binary.cmake: -------------------------------------------------------------------------------- 1 | 2 | execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crt0.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRT0_OBJ) 3 | execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtbegin.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRTBEGIN_OBJ) 4 | execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtend.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRTEND_OBJ) 5 | execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crti.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRTI_OBJ) 6 | execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=crtn.o OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE CRTN_OBJ) 7 | 8 | 9 | set(CMAKE_C_LINK_EXECUTABLE " \"${CRTI_OBJ}\" \"${CRTBEGIN_OBJ}\" \"${CRTEND_OBJ}\" \"${CRTN_OBJ}\" -o .elf ") 10 | set(CMAKE_CXX_LINK_EXECUTABLE " \"${CRTI_OBJ}\" \"${CRTBEGIN_OBJ}\" \"${CRTEND_OBJ}\" \"${CRTN_OBJ}\" -o .elf ") 11 | 12 | 13 | # Config toolchain 14 | if(CONFIG_TOOLCHAIN_PATH) 15 | set(CMAKE_SIZE "${CONFIG_TOOLCHAIN_PATH}/${CONFIG_TOOLCHAIN_PREFIX}size${EXT}") 16 | set(CMAKE_OBJDUMP "${CONFIG_TOOLCHAIN_PATH}/${CONFIG_TOOLCHAIN_PREFIX}objdump${EXT}") 17 | else() 18 | set(CMAKE_SIZE "size${EXT}") 19 | set(CMAKE_SIZE "objdump${EXT}") 20 | endif() 21 | 22 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 23 | COMMAND ${CMAKE_OBJCOPY} --output-format=binary ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.elf ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin 24 | COMMENT "-- Generating .bin firmware at ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin" 25 | ) 26 | 27 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 28 | COMMAND ${CMAKE_SIZE} ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.elf 29 | COMMENT "============= firmware =============" 30 | ) 31 | 32 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 33 | COMMAND ${CMAKE_OBJDUMP} -S ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.elf > ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.txt 34 | ) 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /projects/hello_world/compile/priority.conf: -------------------------------------------------------------------------------- 1 | # component register priority 2 | # The upper components have higher priority 3 | # comments start with `#` 4 | 5 | 6 | kendryte_sdk 7 | main 8 | 9 | -------------------------------------------------------------------------------- /projects/hello_world/config_defaults.mk: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CONFIG_KENDRYTE_SDK_ENABLE=y 5 | CONFIG_SDK_LOG_LEVEL=5 6 | 7 | -------------------------------------------------------------------------------- /projects/hello_world/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ############### Add include ################### 2 | # list(APPEND ADD_INCLUDE "include" 3 | # ) 4 | # list(APPEND ADD_PRIVATE_INCLUDE "") 5 | ############################################### 6 | 7 | ############ Add source files ################# 8 | list(APPEND ADD_SRCS "src/main.c" 9 | ) 10 | # aux_source_directory(src ADD_SRCS) 11 | # list(REMOVE_ITEM COMPONENT_SRCS "src/test2.c") 12 | ############################################### 13 | 14 | ###### Add required/dependent components ###### 15 | list(APPEND ADD_REQUIREMENTS kendryte_sdk) 16 | ############################################### 17 | 18 | ############ Add static libs ################## 19 | # list(APPEND ADD_STATIC_LIB "lib/libtest.a") 20 | ############################################### 21 | 22 | 23 | register_component() 24 | -------------------------------------------------------------------------------- /projects/hello_world/main/src/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include "stdio.h" 3 | #include "global_config.h" 4 | 5 | int main() 6 | { 7 | printf("hello k210\n"); 8 | 9 | while(1){} 10 | } 11 | 12 | -------------------------------------------------------------------------------- /projects/hello_world/project.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #-*- coding = utf-8 -*- 3 | 4 | # 5 | # @file from https://github.com/Neutree/c_cpp_project_framework 6 | # @author neucrack 7 | # @license Apache 2.0 8 | # 9 | 10 | import sys, os 11 | 12 | sdk_env_name = "MY_SDK_PATH" 13 | 14 | # get SDK absolute path 15 | sdk_path = os.path.abspath(sys.path[0]+"/../../") 16 | try: 17 | sdk_path = os.environ[sdk_env_name] 18 | except Exception: 19 | pass 20 | print("-- SDK_PATH:{}".format(sdk_path)) 21 | 22 | # execute project script from SDK 23 | project_file_path = sdk_path+"/tools/cmake/project.py" 24 | with open(project_file_path) as f: 25 | exec(f.read()) 26 | 27 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyserial==3.4 2 | -------------------------------------------------------------------------------- /tools/cmake/compile_flags.cmake: -------------------------------------------------------------------------------- 1 | 2 | 3 | include(${PROJECT_SOURCE_DIR}/compile/compile_flags.cmake) 4 | 5 | -------------------------------------------------------------------------------- /tools/cmake/gen_binary.cmake: -------------------------------------------------------------------------------- 1 | 2 | include(${PROJECT_PATH}/compile/gen_binary.cmake) 3 | 4 | 5 | -------------------------------------------------------------------------------- /tools/cmake/sort_components.py: -------------------------------------------------------------------------------- 1 | # 2 | # sort components according to priority.conf file 3 | # 4 | # @file from https://github.com/Neutree/c_cpp_project_framework 5 | # @author neucrack 6 | # @license Apache 2.0 7 | # 8 | # @usage: python sort_components.py priority.conf component_dir1 component_dir2 ... component_dir4 9 | # 10 | 11 | import sys, os 12 | 13 | conf_file = sys.argv[1] 14 | components = sys.argv[2:] 15 | 16 | if not os.path.exists(conf_file): 17 | exit(2) 18 | 19 | try: 20 | conf = "" 21 | f = open(conf_file) 22 | while True: 23 | line = f.readline() 24 | if not line: 25 | break 26 | line = line.strip() 27 | if line.startswith("#") or line == "": 28 | continue 29 | conf += line +" " 30 | f.close() 31 | except Exception as e: 32 | print("[ERROR] "+str(e)) 33 | exit(1) 34 | 35 | components_ordered = conf.split() 36 | dict_order = {} 37 | for i,component in enumerate(components_ordered): 38 | dict_order[component] = i 39 | 40 | final_components = [] 41 | components_not_ordered = [] 42 | for component in components: # all components 43 | name = os.path.basename(component) 44 | if name in dict_order.keys(): # have priority in config file 45 | find_pos = False 46 | if len(final_components) == 0: 47 | find_pos = True 48 | final_components.append(component) 49 | else: 50 | for j,tmp in enumerate(final_components): 51 | tmp_name = os.path.basename(tmp) 52 | if dict_order[name] < dict_order[tmp_name]: 53 | find_pos = True 54 | final_components.insert(j, component) 55 | break 56 | if not find_pos: 57 | final_components.append(component) 58 | else: # no priority in config file 59 | components_not_ordered.append(component) 60 | final_components += components_not_ordered 61 | 62 | for i in final_components: 63 | print(i, end = ";") 64 | 65 | 66 | -------------------------------------------------------------------------------- /tools/cmake/tools.cmake: -------------------------------------------------------------------------------- 1 | 2 | # add prefix for all list members 3 | # uage: prepend(out_var prefix in_var) 4 | function(prepend out prefix) 5 | set(listVar "") 6 | foreach(f ${ARGN}) 7 | list(APPEND listVar "${prefix}${f}") 8 | endforeach(f) 9 | set(${out} "${listVar}" PARENT_SCOPE) 10 | endfunction() 11 | 12 | # convert all members of list to absolute path(relative to CMAKE_CURRENT_SOURCE_DIR) 13 | # usage: abspath(out_var list_var) 14 | function(abspath out) 15 | set(listVar "") 16 | foreach(f ${ARGN}) 17 | list(APPEND listVar "${CMAKE_CURRENT_SOURCE_DIR}/${f}") 18 | endforeach(f) 19 | set(${out} "${listVar}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | 23 | function(append_srcs_dir out_var) 24 | set(listVar ${${out_var}}) 25 | foreach(f ${ARGN}) 26 | aux_source_directory(${f} tmp) 27 | list(APPEND listVar ${tmp}) 28 | endforeach(f) 29 | set(${out_var} "${listVar}" PARENT_SCOPE) 30 | endfunction() 31 | 32 | -------------------------------------------------------------------------------- /tools/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | 3 | MAINTAINER Sipeed support@sipeed.com 4 | 5 | 6 | RUN DEBIAN_FRONTEND=noninteractive apt-get update -qq \ 7 | && DEBIAN_FRONTEND=noninteractive apt-get install -yq \ 8 | build-essential \ 9 | git \ 10 | wget \ 11 | cmake \ 12 | python3 \ 13 | python3-pip \ 14 | && pip3 install -r https://raw.githubusercontent.com/sipeed/MaixPy/master/requirements.txt \ 15 | && wget https://github.com/kendryte/kendryte-gnu-toolchain/releases/download/v8.2.0-20190409/kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz \ 16 | && tar -Jxf kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz -C /opt \ 17 | && rm -f kendryte-toolchain-ubuntu-amd64-8.2.0-20190409.tar.xz \ 18 | && mkdir /maixpy \ 19 | && echo "setup complete, now clean" \ 20 | && DEBIAN_FRONTEND=noninteractive apt-get autoremove -y --purge \ 21 | && DEBIAN_FRONTEND=noninteractive apt-get clean \ 22 | && rm -rf /var/lib/apt/lists/* \ 23 | && rm -rf /tmp \ 24 | && echo "build complete" 25 | 26 | -------------------------------------------------------------------------------- /tools/docker/README.md: -------------------------------------------------------------------------------- 1 | Docker for MaixPy ( K210 ) 2 | ============= 3 | 4 | ## Get docker image 5 | 6 | ``` 7 | docker pull sipeed/k210_build 8 | ``` 9 | 10 | Use daocloud maybe faster if you are in China 11 | 12 | ``` 13 | docker pull daocloud.io/neucrack/k210_build 14 | ``` 15 | 16 | ## Get source code 17 | 18 | ``` 19 | git clone https://github.com/sipeed/MaixPy.git 20 | cd MaixPy 21 | git submodule update --recursive --init 22 | ``` 23 | 24 | ## Run Docker container 25 | 26 | Just for compile: 27 | 28 | ``` 29 | docker run -it --name maixpy -v `pwd`:/maixpy sipeed/k210_build /bin/bash 30 | ``` 31 | 32 | Or you can connect your devices to container: 33 | 34 | ``` 35 | docker run -it --name maixpy --device /dev/ttyUSB0:/dev/ttyUSB0 -v `pwd`:/maixpy sipeed/k210_build /bin/bash 36 | ``` 37 | 38 | ## Build firmware 39 | 40 | ``` 41 | cd /maixpy 42 | cd projects/hello_world 43 | python3 project.py distclean # if error occures, just ignore 44 | python3 project.py build 45 | ``` 46 | 47 | 48 | ## Burn firmware to board 49 | 50 | * Use [kflash_gui](https://github.com/sipeed/kflash_gui) 51 | 52 | * Or burn in docker container, but you must mount your device to container first, 53 | ``` 54 | python3 project.py flash -p /dev/ttyUSB0 -B dan -b 1500000 -S 55 | ``` 56 | more `flash` command for `project.py` see `python3 project.py --help` 57 | 58 | 59 | -------------------------------------------------------------------------------- /tools/flash/kfpkg.py: -------------------------------------------------------------------------------- 1 | 2 | import json, zipfile, os, tempfile 3 | 4 | class KFPKG(): 5 | def __init__(self): 6 | self.fileInfo = {"version": "0.1.0", "files": []} 7 | self.filePath = {} 8 | self.burnAddr = [] 9 | 10 | def addFile(self, addr, path, prefix=False): 11 | if not os.path.exists(path): 12 | raise ValueError("FilePathError") 13 | if addr in self.burnAddr: 14 | raise ValueError("Burn dddr duplicate"+":0x%06x" %(addr)) 15 | f = {} 16 | f_name = os.path.split(path)[1] 17 | f["address"] = addr 18 | f["bin"] = f_name 19 | f["sha256Prefix"] = prefix 20 | self.fileInfo["files"].append(f) 21 | self.filePath[f_name] = path 22 | self.burnAddr.append(addr) 23 | 24 | def listDumps(self): 25 | kfpkg_json = json.dumps(self.fileInfo, indent=4) 26 | return kfpkg_json 27 | 28 | def listDump(self, path): 29 | with open(path, "w") as f: 30 | f.write(json.dumps(self.fileInfo, indent=4)) 31 | 32 | def listLoads(self, kfpkgJson): 33 | self.fileInfo = json.loads(kfpkgJson) 34 | 35 | def listLload(self, path): 36 | with open(path) as f: 37 | self.fileInfo = json.load(f) 38 | 39 | def save(self, path): 40 | listName = os.path.join(tempfile.gettempdir(), "kflash_gui_tmp_list.json") 41 | self.listDump(listName) 42 | try: 43 | with zipfile.ZipFile(path, "w") as zip: 44 | for name,path in self.filePath.items(): 45 | zip.write(path, arcname=name, compress_type=zipfile.ZIP_DEFLATED) 46 | zip.write(listName, arcname="flash-list.json", compress_type=zipfile.ZIP_DEFLATED) 47 | zip.close() 48 | except Exception as e: 49 | os.remove(listName) 50 | raise e 51 | os.remove(listName) 52 | 53 | -------------------------------------------------------------------------------- /tools/release/.gitignore: -------------------------------------------------------------------------------- 1 | bin -------------------------------------------------------------------------------- /tools/release/release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # 6 | dirty=`git describe --long --tag --dirty --always | awk -F "-" '{print $4}'` 7 | version_full=`git describe --long --tag --dirty --always` 8 | version=`echo $version_full | awk -F "-" '{print $1}'` 9 | version_dev=`echo $version_full | awk -F "-" '{print $2}'` 10 | version_git_rev=`echo $version_full | awk -F "-" '{print $3}'` 11 | if [[ "x$version_dev" != "x" ]]; then 12 | version=${version}_${version_dev}_${version_git_rev} 13 | fi 14 | if [[ "x$dirty" == "xdirty" ]]; then 15 | echo -e "\033[33m [WARNING] coding is dirty!!, please commit all code firstly \033[0m" 16 | git status 17 | fi 18 | echo $version_full 19 | echo $version 20 | 21 | release_dir=`pwd`/bin/mf1_$version 22 | rm -rf $release_dir $release_dir/elf 23 | mkdir -p $release_dir 24 | mkdir -p $release_dir/elf 25 | 26 | # 27 | cd ../../projects 28 | 29 | 30 | # 31 | cd MF1 32 | 33 | ## 1 34 | echo "-------------------" 35 | echo "build project MF1" 36 | echo "long press key clear face feature" 37 | echo "-------------------" 38 | 39 | cp config/config_defaults.mk.1 config_defaults.mk 40 | 41 | python3 project.py distclean 42 | python3 project.py build 43 | cp build/MF1.bin $release_dir/mf1_clr1_$version.bin 44 | cp build/MF1.elf $release_dir/elf/mf1_clr1_$version.elf 45 | 46 | ## 2 47 | echo "-------------------" 48 | echo "build project MF1" 49 | echo "long press key not clear face feature" 50 | echo "-------------------" 51 | 52 | cp config/config_defaults.mk.0 config_defaults.mk 53 | 54 | python3 project.py distclean 55 | python3 project.py build 56 | cp build/MF1.bin $release_dir/mf1_clr0_$version.bin 57 | cp build/MF1.elf $release_dir/elf/mf1_clr0_$version.elf 58 | 59 | ## 3 60 | echo "-------------------" 61 | echo "build project MF1" 62 | echo "key only reset board factory..." 63 | echo "-------------------" 64 | 65 | cp config/config_defaults.mk.2 config_defaults.mk 66 | 67 | python3 project.py distclean 68 | python3 project.py build 69 | cp build/MF1.bin $release_dir/mf1_key_reset_$version.bin 70 | cp build/MF1.elf $release_dir/elf/mf1_key_reset_$version.elf 71 | 72 | 73 | ## 4 74 | echo "-------------------" 75 | echo "build project MF1" 76 | echo "long press key not clear face feature" 77 | echo "LCD display hor 2.4/2.8 inch" 78 | echo "-------------------" 79 | 80 | cp config/config_defaults.mk.3 config_defaults.mk 81 | 82 | python3 project.py distclean 83 | python3 project.py build 84 | cp build/MF1.bin $release_dir/mf1_2_4_inch_$version.bin 85 | cp build/MF1.elf $release_dir/elf/mf1_2_4_inch_$version.elf 86 | 87 | 88 | cd $release_dir 89 | 7z a elf_maixpy_${version}.7z elf/* 90 | rm -rf elf 91 | 92 | ls -al 93 | 94 | 95 | 96 | --------------------------------------------------------------------------------