├── .gitignore ├── pumap ├── vi.c └── vi.h ├── test ├── data │ ├── test_cfg_read │ │ ├── 1.ini │ │ ├── 3.ini │ │ ├── 2.ini │ │ ├── 5.ini │ │ ├── 4.ini │ │ ├── 8.ini │ │ ├── 7.ini │ │ ├── 6.ini │ │ ├── run_tests.sh │ │ └── result.output │ ├── test_ao │ │ └── a-dur.pcm │ ├── test_cfg_sensor │ │ ├── 1.ini │ │ ├── 2.ini │ │ ├── 3.ini │ │ ├── run_tests.sh │ │ └── result.output │ └── test_pumap_vi │ │ ├── vi_gad_ex2 │ │ ├── vi_ds06_majestic │ │ └── vi_gad_ex1 ├── sample_audio │ ├── sample_comm_sys.c │ └── sample_comm_audio.c ├── test_pumap_vi.c ├── used_functions ├── test_tinydraw_0.c ├── test_tinydraw_1.c ├── test_mmz_sdk.c ├── test_mmz.c ├── test_cfg_read.c ├── test_cfg_sensor.c ├── test_ao.c ├── test_tinydraw_2.c ├── test_vi_ext.c ├── test_ao_tiny.c └── test_md.c ├── tools ├── vi_dump.c ├── vi_ive_hist.c ├── pwm1_manager.c ├── hi_vireg.c └── histodiffer.c ├── devices └── BLK18E_0042 │ ├── board_1.jpeg │ ├── board_2.jpeg │ ├── desc.txt │ └── reverse │ ├── i2cdump.txt │ ├── ipctool.txt │ ├── proc-umap-vi.txt │ └── ipctool-reginfo.txt ├── doc ├── IVE.txt └── mmz.txt ├── aux ├── fonts │ ├── monaco.h │ ├── utf8.h │ ├── font.h │ ├── utf8.c │ └── render.h ├── system.h ├── logger.c ├── gmtime.h ├── logger.h ├── system.c └── string.h ├── tinydraw ├── monaco32.h ├── font.h ├── image.c ├── image.h ├── save_bmp.c └── font.c ├── hitiny ├── internal.h ├── hitiny_vda.h ├── hitiny_ive.h ├── hitiny_vi.h ├── hitiny_region.h ├── hitiny_sys.h ├── hitiny_venc.h ├── hitiny_aio.h ├── hitiny_ive.c ├── hitiny_aio.c ├── hitiny_region.c ├── hitiny_ao.c ├── hitiny_vi.c └── hitiny_vda.c ├── platform ├── sdk_ugly.c ├── sdk.h ├── sdk_sensor.c └── sdk_audio_tiny.c ├── README.md ├── cfg ├── common.h ├── vdacfg.h ├── compat.h ├── sensor_cfg_print.c ├── common.c └── sensor_config.h ├── imx225_spi ├── hi_ssp.h └── imx225_sensor_ctl.c ├── evcurl └── evcurl.h ├── cmake └── Modules │ ├── get_hisisdk_ver.py │ └── FindHiSiliconSDK.cmake ├── jxh22_i2c └── hi_i2c.h ├── jxh42_i2c ├── hi_i2c.h └── jxh42_sensor_ctl.c ├── imx225_i2c ├── hi_i2c.h └── imx225_sensor_ctl.c ├── imx225_i2c_960h ├── hi_i2c.h └── imx225_sensor_ctl.c ├── hisinad └── daemon.c ├── libev ├── config.h ├── ev_poll.c └── ev_win32.c └── CMakeLists.txt /.gitignore: -------------------------------------------------------------------------------- 1 | build/* 2 | -------------------------------------------------------------------------------- /pumap/vi.c: -------------------------------------------------------------------------------- 1 | #include "vi.h" 2 | 3 | 4 | -------------------------------------------------------------------------------- /test/data/test_cfg_read/1.ini: -------------------------------------------------------------------------------- 1 | [A] 2 | 3 | [B 4 | 5 | -------------------------------------------------------------------------------- /test/data/test_cfg_read/3.ini: -------------------------------------------------------------------------------- 1 | [A] 2 | 3 | [] 4 | 5 | -------------------------------------------------------------------------------- /test/data/test_cfg_read/2.ini: -------------------------------------------------------------------------------- 1 | [A] 2 | [B] 3 | [ C] 4 | 5 | -------------------------------------------------------------------------------- /test/data/test_cfg_read/5.ini: -------------------------------------------------------------------------------- 1 | [A] 2 | a= 7; 3 | b = qewrcv; 4 | c fg 5 | 6 | -------------------------------------------------------------------------------- /tools/vi_dump.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/hisinad/master/tools/vi_dump.c -------------------------------------------------------------------------------- /tools/vi_ive_hist.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/hisinad/master/tools/vi_ive_hist.c -------------------------------------------------------------------------------- /test/data/test_cfg_read/4.ini: -------------------------------------------------------------------------------- 1 | [A] ; comment... 2 | [B]# comment 3 | [C] wr0ng comment 4 | 5 | -------------------------------------------------------------------------------- /test/data/test_ao/a-dur.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/hisinad/master/test/data/test_ao/a-dur.pcm -------------------------------------------------------------------------------- /devices/BLK18E_0042/board_1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/hisinad/master/devices/BLK18E_0042/board_1.jpeg -------------------------------------------------------------------------------- /devices/BLK18E_0042/board_2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/hisinad/master/devices/BLK18E_0042/board_2.jpeg -------------------------------------------------------------------------------- /pumap/vi.h: -------------------------------------------------------------------------------- 1 | #ifndef __PUMAP_VI_H__ 2 | #define __PUMAP_VI_H__ 3 | 4 | 5 | 6 | 7 | #endif // __PUMAP_VI_H__ 8 | 9 | -------------------------------------------------------------------------------- /devices/BLK18E_0042/desc.txt: -------------------------------------------------------------------------------- 1 | Процессор: Hi3518ev100 2 | Сенсор: Silicon Optronics JX-H42 3 | IRcut gpio: 38,39 4 | 5 | -------------------------------------------------------------------------------- /test/sample_audio/sample_comm_sys.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/hisinad/master/test/sample_audio/sample_comm_sys.c -------------------------------------------------------------------------------- /test/sample_audio/sample_comm_audio.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/hisinad/master/test/sample_audio/sample_comm_audio.c -------------------------------------------------------------------------------- /test/data/test_cfg_read/8.ini: -------------------------------------------------------------------------------- 1 | [A] 2 | a = "a b c"; QQQ!!! 3 | b="b # @@@ cc&^$"# FFF 4 | bb=`17` 5 | bbb = '0x0';!!!! 6 | c="aaaaaa 7 | 8 | -------------------------------------------------------------------------------- /test/data/test_cfg_read/7.ini: -------------------------------------------------------------------------------- 1 | [testing] 2 | fname = /tmp/test.txt ; comment 3 | fname2= /tmp/; comment 4 | fname3 =abc.txt #comment 5 | fname4=abc.txt qaz 6 | -------------------------------------------------------------------------------- /test/test_pumap_vi.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char** argv) 5 | { 6 | 7 | return 0; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /doc/IVE.txt: -------------------------------------------------------------------------------- 1 | HI_MPI_IVE_FILTER 2 | ================= 3 | 4 | Частный случай cv::filter2D() из OpenCV для целочисленного ядра 3х3 и с нормировкой на 2^n. 5 | 6 | 7 | -------------------------------------------------------------------------------- /test/data/test_cfg_sensor/1.ini: -------------------------------------------------------------------------------- 1 | [isp_image] 2 | Isp_x =20 3 | Isp_y =10 4 | Isp_W =1280 5 | Isp_H =720 6 | isp_bayer = BAYER_GBRGx 7 | 8 | 9 | -------------------------------------------------------------------------------- /aux/fonts/monaco.h: -------------------------------------------------------------------------------- 1 | #ifndef _MONACO24_H_ 2 | #define _MONACO24_H_ 3 | 4 | #include 5 | #include "font.h" 6 | 7 | extern font_t monaco32; 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /test/data/test_cfg_read/6.ini: -------------------------------------------------------------------------------- 1 | [AAA] 2 | 3 | aaa= 4 | z = rrr ; comment 5 | a = 56; commect... 6 | b= 0x34 # comment 7 | c=4d#comment 8 | bbb= 555 ff 9 | 10 | -------------------------------------------------------------------------------- /test/data/test_cfg_sensor/2.ini: -------------------------------------------------------------------------------- 1 | [isp_image] 2 | Isp_x =20 3 | Isp_y =10 4 | Isp_W =1280 5 | Isp_H =720 6 | isp_bayer = BAYER_GBRG 7 | 8 | [nonexist] 9 | 10 | -------------------------------------------------------------------------------- /test/data/test_cfg_sensor/3.ini: -------------------------------------------------------------------------------- 1 | [isp_image] 2 | Isp_x =20 3 | Isp_y =10x 4 | Isp_W =1280 5 | Isp_H =720 6 | isp_bayer = BAYER_GBRG 7 | 8 | [nonexist] 9 | 10 | -------------------------------------------------------------------------------- /tinydraw/monaco32.h: -------------------------------------------------------------------------------- 1 | #ifndef __TINYDRAW_MONACO24_H__ 2 | #define __TINYDRAW_MONACO24_H__ 3 | 4 | #include 5 | #include "font.h" 6 | 7 | extern tinydraw_font_t tinydraw_font_monaco32; 8 | 9 | #endif // __TINYDRAW_MONACO24_H__ 10 | 11 | -------------------------------------------------------------------------------- /test/data/test_cfg_read/run_tests.sh: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | 3 | for i in 1 2 3 4 5 6 7 8 ; do ./test_cfg_read ../hisinad/test/data/test_cfg_read/$i.ini ; done &> test_cfg_read.output 4 | diff test_cfg_read.output ../hisinad/test/data/test_cfg_read/result.output 5 | 6 | -------------------------------------------------------------------------------- /test/data/test_cfg_sensor/run_tests.sh: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | 3 | for i in 1 2 3 ; do ./test_cfg_sensor ../hisinad/test/data/test_cfg_sensor/$i.ini ; done &> test_cfg_sensor.output 4 | diff test_cfg_sensor.output ../hisinad/test/data/test_cfg_sensor/result.output 5 | 6 | -------------------------------------------------------------------------------- /test/data/test_cfg_sensor/result.output: -------------------------------------------------------------------------------- 1 | Error CFG_PROC_VALUE_BAD(-30) at line 6, pos 25 2 | Wrong value "BAYER_GBRGx" for isp_bayer 3 | Error CFG_PROC_WRONG_SECTION(-10) at line 8, pos 2 4 | Wrong section name [nonexist] 5 | Error CFG_PROC_VALUE_BAD(-30) at line 3, pos 17 6 | Wrong value "10x" for Isp_y 7 | -------------------------------------------------------------------------------- /test/used_functions: -------------------------------------------------------------------------------- 1 | MPI_VENC_Init(): инитит 64 мутекса для 64 групп, они в g_stMpiVencChn 2 | 3 | HI_MPI_VENC_CreateGroup: на вид реализуема, не понятно что такое g_stMpiVencChn, g_stMpiGrp 4 | 5 | HI_MPI_VENC_CreateChn: 6 | HI_MPI_SYS_Bind 7 | HI_MPI_VENC_RegisterChn 8 | HI_MPI_VENC_StartRecvPic 9 | HI_MPI_VENC_GetFd 10 | HI_MPI_VENC_Query 11 | HI_MPI_VENC_GetStream 12 | HI_MPI_VENC_ReleaseStream 13 | 14 | -------------------------------------------------------------------------------- /hitiny/internal.h: -------------------------------------------------------------------------------- 1 | #ifndef __hitiny_mpi_venc_internal_h__ 2 | #define __hitiny_mpi_venc_internal_h__ 3 | 4 | typedef struct hitiny_MPI_VENC_CHN_S 5 | { 6 | int chn_fd; 7 | 8 | unsigned base_phy; 9 | unsigned base_virtual; 10 | unsigned base_user; 11 | unsigned base_sz; 12 | void* buf_mmap; 13 | unsigned buf_mmap_sz; 14 | } hitiny_MPI_VENC_CHN; 15 | 16 | #endif // __hitiny_mpi_venc_internal_h__ 17 | 18 | -------------------------------------------------------------------------------- /platform/sdk_ugly.c: -------------------------------------------------------------------------------- 1 | #include "sdk.h" 2 | #include 3 | /* ugly sdk hack: start */ 4 | #define MAP_FAILED ((void *)-1) 5 | 6 | void *mmap64(void *start, size_t len, int prot, int flags, int fd, off_t off); 7 | int munmap(void *__addr, size_t __len); 8 | 9 | void *mmap(void *start, size_t len, int prot, int flags, int fd, uint32_t off) { 10 | //fprintf(stderr, "MMAP OUR! fd = %d, off = 0x%u\n", fd, off); 11 | return mmap64(start, len, prot, flags, fd, off); 12 | } 13 | /* ugly sdk hack: end */ 14 | -------------------------------------------------------------------------------- /test/data/test_cfg_read/result.output: -------------------------------------------------------------------------------- 1 | [A] 2 | Syntax error at line 3, pos 3 3 | [A] 4 | [B] 5 | Syntax error at line 3, pos 2 6 | [A] 7 | Syntax error at line 3, pos 3 8 | [A] 9 | [B] 10 | [C] 11 | Syntax error at line 3, pos 8 12 | [A] 13 | a=7 14 | b=qewrcv 15 | Syntax error at line 4, pos 4 16 | [AAA] 17 | aaa= 18 | z=rrr 19 | a=56 20 | b=0x34 21 | c=4d 22 | Syntax error at line 8, pos 11 23 | [testing] 24 | fname=/tmp/test.txt 25 | fname2=/tmp/ 26 | fname3=abc.txt 27 | Syntax error at line 5, pos 16 28 | [A] 29 | a=a b c 30 | b=b # @@@ cc&^$ 31 | bb=17 32 | bbb=0x0 33 | Syntax error at line 6, pos 11 34 | -------------------------------------------------------------------------------- /hitiny/hitiny_vda.h: -------------------------------------------------------------------------------- 1 | #ifndef __hitiny_vda_h__ 2 | #define __hitiny_vda_h__ 3 | 4 | #include "hi_comm_vda.h" 5 | 6 | void hitiny_vda_init(); 7 | void hitiny_vda_done(); 8 | 9 | int hitiny_MPI_VDA_CreateChn(VDA_CHN VdaChn, const VDA_CHN_ATTR_S *pstAttr); 10 | int hitiny_MPI_VDA_DestroyChn(VDA_CHN VdaChn); 11 | 12 | int hitiny_MPI_VDA_GetFd(unsigned VdaChn); 13 | 14 | int hitiny_MPI_VDA_StartRecvPic(VDA_CHN VdaChn); 15 | int hitiny_MPI_VDA_StopRecvPic(VDA_CHN VdaChn); 16 | 17 | int hitiny_MPI_VDA_GetData(VDA_CHN VdaChn, VDA_DATA_S *pstVdaData, HI_BOOL bBlock); 18 | int hitiny_MPI_VDA_ReleaseData(VDA_CHN VdaChn, const VDA_DATA_S* pstVdaData); 19 | 20 | 21 | #endif //__hitiny_vda_h__ 22 | 23 | -------------------------------------------------------------------------------- /hitiny/hitiny_ive.h: -------------------------------------------------------------------------------- 1 | #ifndef __HITINY_IVE_H__ 2 | #define __HITINY_IVE_H__ 3 | 4 | #include "hi_comm_ive.h" 5 | 6 | #ifdef __cplusplus 7 | #if __cplusplus 8 | extern "C"{ 9 | #endif 10 | #endif 11 | 12 | int hitiny_ive_fd(); 13 | 14 | 15 | int hitiny_MPI_IVE_HIST(IVE_HANDLE *pIveHandle, IVE_SRC_INFO_S *pstSrc, IVE_MEM_INFO_S *pstDst, HI_BOOL bInstant); 16 | int hitiny_MPI_IVE_FILTER(IVE_HANDLE *pIveHandle, IVE_SRC_INFO_S *pstSrc, IVE_MEM_INFO_S *pstDst, IVE_FILTER_CTRL_S *pstFilterCtrl,HI_BOOL bInstant); 17 | 18 | int hitiny_MPI_IVE_Query(IVE_HANDLE IveHandle, HI_BOOL *pbFinish, HI_BOOL bBlock); 19 | 20 | 21 | #ifdef __cplusplus 22 | #if __cplusplus 23 | } 24 | #endif 25 | #endif 26 | #endif // __HITINY_IVE_H__ 27 | 28 | -------------------------------------------------------------------------------- /test/test_tinydraw_0.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char** argv) 4 | { 5 | tinydraw_renderer_ctx_t td_ctx; 6 | tinydraw_renderer_ctx_init(&td_ctx, 10, 10, 16); 7 | 8 | for (unsigned x = 0; x < 5; ++x) 9 | for (unsigned y = 0; y < 5; ++y) tinydraw_renderer_draw_pixel(&td_ctx, x, y, RED_COLOR); 10 | 11 | for (unsigned x = 0; x < 5; ++x) 12 | for (unsigned y = 5; y < 10; ++y) tinydraw_renderer_draw_pixel(&td_ctx, x, y, GREEN_COLOR); 13 | 14 | for (unsigned x = 8; x < 10; ++x) 15 | for (unsigned y = 3; y < 7; ++y) tinydraw_renderer_draw_pixel(&td_ctx, x, y, BLUE_COLOR); 16 | 17 | tinydraw_renderer_save_bmp(&td_ctx, "test.bmp"); 18 | tinydraw_renderer_ctx_done(&td_ctx); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## hisinad 2 | 3 | Experiments with hi3516cv100 (and similar v1 Hisilicon SoCs). 4 | 5 | Please contact pianisteg.mobile@gmail.com for any questions. 6 | 7 | ## How to compile? 8 | 9 | You can build hisinad for arm and for your desktop platform. Just create two folders — for example, `build_arm` and `build_pc`. 10 | 11 | Some utilities and tests can be compiled for any platform: 12 | 13 | ``` 14 | cmake -DPLATFORM_SDK_DIR=/path/to/hisilicon_sdk/ ../hisinad/ 15 | ``` 16 | 17 | Hardware-specific software — only for target platform, please set path to toolchain: 18 | 19 | ``` 20 | cmake -DPLATFORM_SDK_DIR=/path/to/hisilicon_sdk/ -DCMAKE_TOOLCHAIN_FILE=/path/to/openipc-firmware/output/host/share/buildroot/toolchainfile.cmake ../hisinad/ 21 | ``` 22 | 23 | test line 24 | 25 | -------------------------------------------------------------------------------- /cfg/common.h: -------------------------------------------------------------------------------- 1 | #ifndef __CFG_COMMON_H__ 2 | #define __CFG_COMMON_H__ 3 | 4 | #include 5 | 6 | #define CFG_PROC_OK 0 7 | #define CFG_PROC_IO -1 8 | #define CFG_PROC_SYNTAX -2 9 | #define CFG_PROC_WRONG_SECTION -10 10 | #define CFG_PROC_KEY_BAD -20 11 | #define CFG_PROC_KEY_DUP -21 12 | #define CFG_PROC_VALUE_BAD -30 13 | 14 | typedef int (*cfg_proc_new_section)(const char* s); 15 | typedef int (*cfg_proc_new_key_value)(const char* k, const char* v); 16 | 17 | int cfg_proc_read(const char* fname, cfg_proc_new_section _new_sec, cfg_proc_new_key_value _new_kv); 18 | unsigned cfg_proc_err_line_num(); 19 | unsigned cfg_proc_err_line_pos(); 20 | 21 | const char* cfg_proc_err_msg(int err); 22 | 23 | 24 | #endif // __CFG_COMMON_H__ 25 | 26 | -------------------------------------------------------------------------------- /tools/pwm1_manager.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main(int argc, char** argv) 10 | { 11 | if (argc < 2) 12 | { 13 | fprintf(stderr, "usage: %s NUM (/1000)\n", argv[0]); 14 | return -1; 15 | } 16 | 17 | unsigned duty = atoi(argv[1]); 18 | if (duty > 1000) duty = 1000; 19 | 20 | int fd_pwm = open("/dev/pwm", 0); 21 | 22 | if (fd_pwm < 0) 23 | { 24 | fprintf(stderr, "can't open /dev/pwm\n"); 25 | return -1; 26 | } 27 | 28 | unsigned param[4]; 29 | param[0] = 1; // PWM1 30 | param[1] = duty; 31 | param[2] = 1000; 32 | param[3] = (duty > 0) ? 1 : 0; 33 | 34 | ioctl(fd_pwm, 1, param); 35 | 36 | close(fd_pwm); 37 | 38 | return 0; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /hitiny/hitiny_vi.h: -------------------------------------------------------------------------------- 1 | #ifndef __hitiny_mpi_h__ 2 | #define __hitiny_mpi_h__ 3 | 4 | #include "hi_comm_vi.h" 5 | 6 | void hitiny_MPI_VI_Init(); 7 | void hitiny_MPI_VI_Done(); 8 | 9 | int hitiny_MPI_VI_SetExtChnAttr(VI_CHN ViChn, const VI_EXT_CHN_ATTR_S *pstExtChnAttr); 10 | int hitiny_MPI_VI_GetExtChnAttr(VI_CHN ViChn, VI_EXT_CHN_ATTR_S *pstExtChnAttr); 11 | 12 | int hitiny_MPI_VI_EnableChn(VI_CHN ViChn); 13 | int hitiny_MPI_VI_DisableChn(VI_CHN ViChn); 14 | 15 | int hitiny_MPI_VI_GetFd(VI_CHN ViChn); 16 | 17 | int hitiny_MPI_VI_GetFrame(VI_CHN ViChn, VIDEO_FRAME_INFO_S *pstFrameInfo); 18 | int hitiny_MPI_VI_GetFrameTimeOut(VI_CHN ViChn, VIDEO_FRAME_INFO_S *pstFrameInfo, unsigned u32MilliSec); 19 | int hitiny_MPI_VI_ReleaseFrame(VI_CHN ViChn, VIDEO_FRAME_INFO_S *pstFrameInfo); 20 | int hitiny_MPI_VI_SetFrameDepth(VI_CHN ViChn, unsigned u32Depth); 21 | int hitiny_MPI_VI_GetFrameDepth(VI_CHN ViChn, unsigned *pu32Depth); 22 | 23 | #endif // __hitiny_mpi_h__ 24 | 25 | -------------------------------------------------------------------------------- /hitiny/hitiny_region.h: -------------------------------------------------------------------------------- 1 | #ifndef __hitiny_region_h__ 2 | #define __hitiny_region_h__ 3 | 4 | #include "hi_comm_region.h" 5 | 6 | int hitiny_region_init(); 7 | void hitiny_region_done(); 8 | 9 | int hitiny_MPI_RGN_Create(RGN_HANDLE Handle,const RGN_ATTR_S *pstRegion); 10 | int hitiny_MPI_RGN_Destroy(RGN_HANDLE Handle); 11 | 12 | int hitiny_MPI_RGN_GetAttr(RGN_HANDLE Handle,RGN_ATTR_S *pstRegion); 13 | int hitiny_MPI_RGN_SetAttr(RGN_HANDLE Handle,const RGN_ATTR_S *pstRegion); 14 | 15 | int hitiny_MPI_RGN_SetBitMap(RGN_HANDLE Handle,const BITMAP_S *pstBitmap); 16 | 17 | //HI_S32 hitiny_MPI_RGN_SetAttachField(RGN_HANDLE Handle, RGN_ATTACH_FIELD_E enAttachField); 18 | //HI_S32 hitiny_MPI_RGN_GetAttachField(RGN_HANDLE Handle, RGN_ATTACH_FIELD_E *penAttachField); 19 | 20 | int hitiny_MPI_RGN_AttachToChn(RGN_HANDLE Handle,const MPP_CHN_S *pstChn,const RGN_CHN_ATTR_S *pstChnAttr); 21 | int hitiny_MPI_RGN_DetachFrmChn(RGN_HANDLE Handle,const MPP_CHN_S *pstChn); 22 | 23 | 24 | #endif //__hitiny_region_h__ 25 | 26 | -------------------------------------------------------------------------------- /imx225_spi/hi_ssp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * extdrv/include/hi_ssp.h for Linux . 3 | * 4 | * History: 5 | * 2006-4-11 create this file 6 | */ 7 | 8 | #ifndef __HI_SSP_H__ 9 | #define __HI_SSP_H__ 10 | 11 | #define SSP_READ_ALT 0x1 12 | #define SSP_WRITE_ALT 0X3 13 | 14 | int hi_ssp_set_frameform(unsigned char framemode,unsigned char spo,unsigned char sph,unsigned char datawidth); 15 | int hi_ssp_readdata(void); 16 | void hi_ssp_writedata(unsigned short data); 17 | 18 | void hi_ssp_enable(void); 19 | void hi_ssp_disable(void); 20 | 21 | int hi_ssp_set_serialclock(unsigned char,unsigned char); 22 | 23 | void hi_ssp_dmac_enable(void); 24 | void hi_ssp_dmac_disable(void); 25 | 26 | int hi_ssp_dmac_init(void *,void *); 27 | void hi_ssp_dmac_exit(void); 28 | int hi_ssp_dmac_transfer(unsigned int,unsigned int,unsigned int); 29 | 30 | int hi_ssp_write(unsigned int addr1, unsigned int addr1bytenum, 31 | unsigned int addr2, unsigned int addr2bytenum, 32 | unsigned int data ,unsigned int databytenum); 33 | 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /aux/system.h: -------------------------------------------------------------------------------- 1 | #ifndef __AUX_SYSTEM_H__ 2 | #define __AUX_SYSTEM_H__ 3 | 4 | #include 5 | #ifndef __NO_MMAN__ 6 | #include 7 | #endif 8 | #include 9 | #include 10 | #include "string.h" 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | int aux_fdopen(int fd, const char *path, int flags); 17 | int aux_fdmove(int fd, int nd); 18 | 19 | #define aux_fnopen(p,f) open((const char *) p, f, 0644) 20 | #define aux_mkfold(p) mkdir((const char *) p, 0755) 21 | #define aux_rmfold(p) rmdir((const char *) p) 22 | #define aux_rmfile(p) unlink((const char *) p) 23 | #define aux_rlpath(p) realpath((const char *) p, alloca(PATH_MAX)) 24 | 25 | int aux_mkpath(char *path); 26 | int aux_mkpidf(const char *path); 27 | 28 | int aux_mmap(strp area, int prot_flags, int mmap_flags, const char *filename); 29 | 30 | #define aux_umap(area) munmap((area)->data, (area)->size) 31 | #define aux_mmap_file(a,p) aux_mmap((strp) aux_clrptr(a), PROT_READ, MAP_PRIVATE, p) 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif /* __AUX_SYSTEM_H__ */ 38 | -------------------------------------------------------------------------------- /platform/sdk.h: -------------------------------------------------------------------------------- 1 | #ifndef __platform_sdk_h__ 2 | #define __platform_sdk_h__ 3 | 4 | #include 5 | #include 6 | 7 | extern const char* __sdk_last_call; 8 | 9 | void set_verbose_level(int lvl); 10 | 11 | int sdk_init(const struct SensorConfig* sc); 12 | void sdk_done(); 13 | 14 | int sdk_audio_init(int bMic, PAYLOAD_TYPE_E payload_type, int audio_rate); 15 | void sdk_audio_done(); 16 | 17 | /* ret -1: error, 0: played ok to the end, 1: playing interrupted with stop_flag */ 18 | int sdk_audio_play(FILE* f, int* stop_flag); 19 | 20 | 21 | int sdk_sensor_init(const struct SensorConfig* sc); 22 | int sdk_isp_init(const struct SensorConfig* sc); 23 | int sdk_vi_init(const struct SensorConfig* sc); 24 | int sdk_vpss_init(const struct SensorConfig* sc); 25 | void sdk_vi_done(); 26 | void sdk_isp_done(); 27 | void sdk_sensor_done(); 28 | 29 | 30 | #if HISILICON_SDK_GEN == 1 31 | //#include 32 | #elif HISILICON_SDK_GEN == 2 33 | //# error "hisi v2 is not ready, sorry" 34 | #else 35 | # error "platform not defined" 36 | #endif 37 | 38 | 39 | 40 | #endif // __platform_sdk_h__ 41 | 42 | -------------------------------------------------------------------------------- /aux/logger.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "logger.h" 6 | 7 | volatile int log_level = LOG_info; 8 | 9 | int log_levels(const char* level) 10 | { 11 | switch (level[0]) 12 | { 13 | case 'a': case 'A': 14 | switch (level[1]) 15 | { 16 | case 'c': case 'C': return LOG_access; 17 | case 'l': case 'L': return LOG_alert; 18 | } 19 | break; 20 | case 'd': case 'D': return LOG_debug; 21 | case 'c': case 'C': return LOG_crit; 22 | case 'e': case 'E': 23 | switch (level[1]) 24 | { 25 | case 'm': case 'M': return LOG_emerg; 26 | case 'r': case 'R': return LOG_error; 27 | } 28 | break; 29 | case 'i': case 'I': return LOG_info; 30 | case 'n': case 'N': return LOG_notice; 31 | case 'w': case 'W': return LOG_warn; 32 | } 33 | 34 | return LOG_info; /* default */ 35 | } 36 | 37 | int log_create(const char* path, int level) 38 | { 39 | if (0 > aux_mkpath((char *) path)) return -1; 40 | if (0 > aux_fdopen(STDERR_FILENO, path, O_CREAT|O_APPEND|O_WRONLY)) return -1; 41 | 42 | log_level = level; 43 | 44 | return STDERR_FILENO; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /test/test_tinydraw_1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char** argv) 5 | { 6 | tinydraw_renderer_ctx_t td_ctx; 7 | tinydraw_renderer_ctx_init(&td_ctx, 50, 50, 16); 8 | 9 | for (unsigned x = 0; x < 5; ++x) 10 | for (unsigned y = 0; y < 5; ++y) tinydraw_renderer_draw_pixel(&td_ctx, x, y, RED_COLOR); 11 | 12 | for (unsigned x = 0; x < 5; ++x) 13 | for (unsigned y = 5; y < 10; ++y) tinydraw_renderer_draw_pixel(&td_ctx, x, y, GREEN_COLOR); 14 | 15 | for (unsigned x = 8; x < 10; ++x) 16 | for (unsigned y = 3; y < 7; ++y) tinydraw_renderer_draw_pixel(&td_ctx, x, y, BLUE_COLOR); 17 | 18 | tinydraw_renderer_draw_char(&td_ctx, 10, 0, &tinydraw_font_monaco32, 'A'); 19 | tinydraw_renderer_draw_char(&td_ctx, 40, 0, &tinydraw_font_monaco32, 'B'); 20 | tinydraw_renderer_draw_char(&td_ctx, 15, 35, &tinydraw_font_monaco32, 'Y'); 21 | tinydraw_renderer_draw_char(&td_ctx, 35, 35, &tinydraw_font_monaco32, 'W'); 22 | 23 | tinydraw_renderer_save_bmp(&td_ctx, "test.bmp"); 24 | tinydraw_renderer_ctx_done(&td_ctx); 25 | 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /tinydraw/font.h: -------------------------------------------------------------------------------- 1 | #ifndef __TINYDRAW_FONT_H__ 2 | #define __TINYDRAW_FONT_H__ 3 | 4 | #include 5 | #include 6 | #include "image.h" 7 | 8 | #define FONT_MARGIN_DATABIT_SIZE 6 9 | 10 | typedef uint32_t utf8_char_t; 11 | 12 | typedef struct 13 | { 14 | uint8_t margin_top :FONT_MARGIN_DATABIT_SIZE; 15 | uint8_t margin_bottom :FONT_MARGIN_DATABIT_SIZE; 16 | uint8_t margin_left :FONT_MARGIN_DATABIT_SIZE; 17 | uint8_t margin_right :FONT_MARGIN_DATABIT_SIZE; 18 | 19 | uint16_t bmp_index; 20 | 21 | } tinydraw_font_symbol_t; 22 | 23 | typedef bool (*fnt_lookup_fp)(utf8_char_t c, tinydraw_font_symbol_t *sym); 24 | 25 | typedef struct 26 | { 27 | uint8_t width; 28 | uint8_t height; 29 | 30 | const uint8_t *bmp_base; 31 | 32 | fnt_lookup_fp lookup; 33 | } tinydraw_font_t; 34 | 35 | void tinydraw_renderer_draw_char(tinydraw_renderer_ctx_t *ctx, uint16_t x, uint16_t y, const tinydraw_font_t *fnt, utf8_char_t c); 36 | void tinydraw_renderer_draw_string(tinydraw_renderer_ctx_t *ctx, uint16_t x, uint16_t y, const tinydraw_font_t *fnt, const char* s); 37 | 38 | #endif // __TINYDRAW_FONT_H__ 39 | 40 | -------------------------------------------------------------------------------- /hitiny/hitiny_sys.h: -------------------------------------------------------------------------------- 1 | #ifndef __HITINY_SYS_H__ 2 | #define __HITINY_SYS_H__ 3 | 4 | #include "hi_common.h" 5 | 6 | int hitiny_MPI_SYS_Init(); 7 | void hitiny_MPI_SYS_Done(); 8 | 9 | int hitiny_sys_bind_VPSS_GROUP(int vpss_dev_id, int vpss_chn_id, int grp_id); 10 | int hitiny_sys_unbind_VPSS_GROUP(int vpss_dev_id, int vpss_chn_id, int grp_id); 11 | 12 | int hitiny_sys_bind_VI_VDA(int vi_dev, int vi_chn, int vda_chn); 13 | int hitiny_sys_unbind_VI_VDA(int vi_dev, int vi_chn, int vda_chn); 14 | 15 | int hitiny_open_dev(const char* fname); 16 | 17 | void* hitiny_MPI_SYS_Mmap(HI_U32 u32PhyAddr, HI_U32 u32Size); 18 | int hitiny_MPI_SYS_Munmap(HI_VOID* pVirAddr, HI_U32 u32Size); 19 | 20 | int hitiny_MPI_SYS_MmzAlloc(HI_U32 *pu32PhyAddr, HI_VOID **ppVirtAddr, const HI_CHAR *strMmb, const HI_CHAR *strZone, HI_U32 u32Len); 21 | int hitiny_MPI_SYS_MmzAlloc_Cached(HI_U32 *pu32PhyAddr, HI_VOID **ppVirtAddr, const HI_CHAR *strMmb, const HI_CHAR *strZone, HI_U32 u32Len); 22 | int hitiny_MPI_SYS_MmzFree(HI_U32 u32PhyAddr, HI_VOID *pVirtAddr); 23 | int hitiny_MPI_SYS_MmzFlushCache(HI_U32 u32PhyAddr, HI_VOID *pVirtAddr, HI_U32 u32Size); 24 | 25 | 26 | 27 | #endif // __HITINY_SYS_H__ 28 | 29 | -------------------------------------------------------------------------------- /aux/fonts/utf8.h: -------------------------------------------------------------------------------- 1 | /* Extract some utf-8 functions from https://github.com/vigna/ne/blob/master/src/utf8.c */ 2 | 3 | /* UTF-8 support. 4 | Copyright (C) 1993-1998 Sebastiano Vigna 5 | Copyright (C) 1999-2021 Todd M. Lewis and Sebastiano Vigna 6 | This file is part of ne, the nice editor. 7 | This library is free software; you can redistribute it and/or modify it 8 | under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | This library is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | for more details. 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . */ 17 | 18 | 19 | #ifndef _UTF8_H_ 20 | #define _UTF8_H_ 21 | 22 | #include 23 | 24 | typedef uint32_t utf8_t; 25 | 26 | uint8_t utf8_charlen(utf8_t c); 27 | utf8_t utf8_getchar(const char * const ss); 28 | 29 | #endif -------------------------------------------------------------------------------- /hitiny/hitiny_venc.h: -------------------------------------------------------------------------------- 1 | #ifndef __platform_x_mpi_venc_h__ 2 | #define __platform_x_mpi_venc_h__ 3 | 4 | #include "hi_comm_venc.h" 5 | 6 | void hitiny_MPI_VENC_Init(); 7 | void hitiny_MPI_VENC_Done(); 8 | 9 | int hitiny_MPI_VENC_CreateGroup(VENC_GRP VeGroup); 10 | int hitiny_MPI_VENC_DestroyGroup(VENC_GRP VeGroup); 11 | 12 | int hitiny_MPI_VENC_CreateChn(VENC_CHN VeChn, const VENC_CHN_ATTR_S *pstAttr); 13 | int hitiny_MPI_VENC_DestroyChn(VENC_CHN VeChn); 14 | 15 | int hitiny_MPI_VENC_RegisterChn(VENC_GRP VeGroup, VENC_CHN VeChn); 16 | int hitiny_MPI_VENC_UnRegisterChn(VENC_CHN VeChn); 17 | 18 | int hitiny_MPI_VENC_GetFd(VENC_CHN VeChn); 19 | 20 | int hitiny_MPI_VENC_StartRecvPic(VENC_CHN VeChn); 21 | int hitiny_MPI_VENC_StopRecvPic(VENC_CHN VeChn); 22 | 23 | int hitiny_MPI_VENC_Query(VENC_CHN VeChn, VENC_CHN_STAT_S *pstStat); 24 | int hitiny_MPI_VENC_GetStream(VENC_CHN VeChn, VENC_STREAM_S *pstStream, HI_BOOL bBlockFlag); 25 | int hitiny_MPI_VENC_ReleaseStream(VENC_CHN VeChn, VENC_STREAM_S *pstStream); 26 | 27 | int hitiny_MPI_VENC_SetColor2GreyConf(const GROUP_COLOR2GREY_CONF_S *pstGrpColor2GreyConf); 28 | int hitiny_MPI_VENC_SetGrpColor2Grey(VENC_GRP VeGroup, const GROUP_COLOR2GREY_S *pstGrpColor2Grey); 29 | 30 | #endif // __platform_x_mpi_venc_h__ 31 | 32 | -------------------------------------------------------------------------------- /test/test_mmz_sdk.c: -------------------------------------------------------------------------------- 1 | #include "mpi_sys.h" 2 | #include 3 | 4 | #define SZ_ARRAY 4096 5 | 6 | void do_test(unsigned* ptr) 7 | { 8 | for (unsigned i = 0; i < SZ_ARRAY; ++i) ptr[i] = (i + 1) * (i + 1); 9 | 10 | unsigned long long sum = 0; 11 | for (unsigned i = 0; i < SZ_ARRAY; ++i) sum += ptr[i]; 12 | 13 | unsigned long long xsum = SZ_ARRAY + 1; 14 | xsum *= 2 * SZ_ARRAY + 1; 15 | xsum *= SZ_ARRAY; 16 | xsum /= 6; 17 | 18 | log_info("sum 1^2 + 2^2 + ... + %u^2 = %llu, have to be %llu", SZ_ARRAY, sum, xsum); 19 | } 20 | 21 | int main(int argc, char** argv) 22 | { 23 | unsigned phy_addr; 24 | void* ptr; 25 | 26 | int r = HI_MPI_SYS_MmzAlloc_Cached(&phy_addr, &ptr, "usr-tester", 0, SZ_ARRAY * sizeof(unsigned)); 27 | log_info("MMZ ALLOC returned %u (0 is OK)", r); 28 | if (r) return r; 29 | 30 | log_info("PHY addr 0x%x, virt 0x%x", phy_addr, ptr); 31 | 32 | memset(ptr, 0, SZ_ARRAY * sizeof(unsigned)); 33 | r = HI_MPI_SYS_MmzFlushCache(phy_addr, ptr, SZ_ARRAY * sizeof(unsigned)); 34 | //r = HI_MPI_SYS_MmzFlushCache(0, 0, 0); 35 | log_info("MMZ FLUSH returned 0x%x (0 is OK)", r); 36 | 37 | do_test(ptr); 38 | 39 | r = HI_MPI_SYS_MmzFree(phy_addr, ptr); 40 | log_info("MMZ FREE returned %u (0 is OK)", r); 41 | 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /test/test_mmz.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define SZ_ARRAY 4096 5 | 6 | void do_test(unsigned* ptr) 7 | { 8 | for (unsigned i = 0; i < SZ_ARRAY; ++i) ptr[i] = (i + 1) * (i + 1); 9 | 10 | unsigned long long sum = 0; 11 | for (unsigned i = 0; i < SZ_ARRAY; ++i) sum += ptr[i]; 12 | 13 | unsigned long long xsum = SZ_ARRAY + 1; 14 | xsum *= 2 * SZ_ARRAY + 1; 15 | xsum *= SZ_ARRAY; 16 | xsum /= 6; 17 | 18 | log_info("sum 1^2 + 2^2 + ... + %u^2 = %llu, have to be %llu", SZ_ARRAY, sum, xsum); 19 | } 20 | 21 | int main(int argc, char** argv) 22 | { 23 | unsigned phy_addr; 24 | void* ptr; 25 | 26 | int r = hitiny_MPI_SYS_MmzAlloc_Cached(&phy_addr, &ptr, "usr-tester", 0, SZ_ARRAY * sizeof(unsigned)); 27 | log_info("MMZ ALLOC returned %u (0 is OK)", r); 28 | if (r) return r; 29 | 30 | log_info("PHY addr 0x%x, virt 0x%x", phy_addr, ptr); 31 | 32 | memset(ptr, 0, SZ_ARRAY * sizeof(unsigned)); 33 | r = hitiny_MPI_SYS_MmzFlushCache(phy_addr, ptr, SZ_ARRAY * sizeof(unsigned)); 34 | //r = hitiny_MPI_SYS_MmzFlushCache(0, 0, 0); 35 | log_info("MMZ FLUSH returned 0x%x (0 is OK)", r); 36 | 37 | do_test(ptr); 38 | 39 | r = hitiny_MPI_SYS_MmzFree(phy_addr, ptr); 40 | log_info("MMZ FREE returned %u (0 is OK)", r); 41 | 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /cfg/vdacfg.h: -------------------------------------------------------------------------------- 1 | #ifndef __hisinad_vda_config_h_ 2 | #define __hisinad_vda_config_h_ 3 | 4 | struct vda_cfg_vi_chn_s 5 | { 6 | unsigned vi_chnl; 7 | unsigned width; 8 | unsigned height; 9 | }; 10 | 11 | enum VPSS_CHN_E 12 | { 13 | VPSS_CHN_UNSET = -1, 14 | VPSS_CHN_CHN0 = 0, 15 | VPSS_CHN_CHN1 = 1, 16 | VPSS_CHN_BYPASS = 2, 17 | }; 18 | 19 | extern const char *cfg_daemon_vals_vpss_chn[]; 20 | 21 | struct mjpeg_snap_s 22 | { 23 | enum VPSS_CHN_E vpss_chn; 24 | unsigned grp_id; 25 | unsigned venc_chn_id; 26 | 27 | unsigned width; 28 | unsigned height; 29 | 30 | unsigned vbr_stat_time; 31 | unsigned vbr_vi_frm_rate; 32 | unsigned vbr_target_frm_rate; 33 | unsigned vbr_Max_bitrate; 34 | unsigned vbr_Max_Qfactor; 35 | unsigned vbr_Min_Qfactor; 36 | 37 | char upload_url[256]; 38 | char upload_username[64]; 39 | char upload_password[64]; 40 | }; 41 | 42 | struct vda_md_s 43 | { 44 | unsigned VdaChn; 45 | unsigned VdaIntvl; 46 | unsigned SadTh; 47 | unsigned ObjNumMax; 48 | }; 49 | 50 | struct vda_cfg_s 51 | { 52 | struct vda_cfg_vi_chn_s vi; 53 | struct mjpeg_snap_s mjpeg_snap; 54 | struct vda_md_s md; 55 | }; 56 | 57 | int vda_cfg_read(const char* fname, struct vda_cfg_s* vc); 58 | const char* vda_cfg_read_error_key(); 59 | const char* vda_cfg_read_error_value(); 60 | 61 | #endif // __hisinad_vda_config_h_ 62 | 63 | -------------------------------------------------------------------------------- /devices/BLK18E_0042/reverse/i2cdump.txt: -------------------------------------------------------------------------------- 1 | # ./ipctool-2024-03-26 i2cdump 0x60 0x0 0xff 2 | 0 1 2 3 4 5 6 7 8 9 A B C D E F 3 | : 4F 32 07 FF FF FF FF FF FF 81 A0 42 00 45 1D 0B | O2.........B.E.. 4 | 10: 26 80 00 67 80 44 C0 40 E6 00 80 49 FF FF 9F 04 | &..g.D.@...I.... 5 | 20: 72 06 34 07 00 DC 25 3B 0B 01 24 29 04 00 BB 00 | r.4...%;..$).... 6 | 30: FF FF FF 00 38 54 00 40 38 92 00 00 08 10 08 10 | ....8T.@8....... 7 | 40: 08 24 41 50 50 50 50 00 60 10 03 F4 1F 1C F1 AA | .$APPPP.`....... 8 | 50: 00 01 2F 2D 00 EB EB EB EB EB 08 08 08 08 08 08 | ../-............ 9 | 60: A4 FF 40 51 15 00 10 30 04 74 01 00 90 02 0C 04 | ..@Q...0.t...... 10 | 70: 68 8A 68 B3 53 2B 40 06 14 14 14 14 14 14 14 14 | h.h.S+@......... 11 | 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................ 12 | 90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................ 13 | a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................ 14 | b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................ 15 | c0: 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A | ................ 16 | d0: 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A | ................ 17 | e0: 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A | ................ 18 | f0: 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A | ................ 19 | 20 | -------------------------------------------------------------------------------- /test/test_cfg_read.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int my_simple_sec_cb(const char* s) 6 | { 7 | printf("[%s]\n", s); 8 | return CFG_PROC_OK; 9 | } 10 | 11 | int my_simple_kv_cb(const char* k, const char* v) 12 | { 13 | printf("%s=%s\n", k, v); 14 | return CFG_PROC_OK; 15 | } 16 | 17 | 18 | int main(int argc, char** argv) 19 | { 20 | if (argc != 2) 21 | { 22 | printf("Usage: ./test_cfg_reader config.ini\n"); 23 | return -1; 24 | } 25 | 26 | int ret = cfg_proc_read(argv[1], my_simple_sec_cb, my_simple_kv_cb); 27 | switch (ret) 28 | { 29 | case CFG_PROC_IO: 30 | { 31 | printf("I/O error, %d: %s\n", errno, strerror(errno)); 32 | break; 33 | } 34 | case CFG_PROC_SYNTAX: 35 | { 36 | printf("Syntax error at line %u, pos %u\n", cfg_proc_err_line_num(), cfg_proc_err_line_pos()); 37 | break; 38 | } 39 | case CFG_PROC_WRONG_SECTION: 40 | { 41 | printf("Wrong section name at line %u, pos %u\n", cfg_proc_err_line_num(), cfg_proc_err_line_pos()); 42 | break; 43 | } 44 | case CFG_PROC_OK: 45 | { 46 | break; 47 | } 48 | default: 49 | { 50 | printf("Unknown error %d\n", ret); 51 | break; 52 | } 53 | } 54 | 55 | return 0; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /test/test_cfg_sensor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | 8 | int main(int argc, char** argv) 9 | { 10 | if (argc != 2) 11 | { 12 | printf("Usage: ./test_cfg_reader config.ini\n"); 13 | return -1; 14 | } 15 | 16 | struct SensorConfig sc; 17 | memset(&sc, 0, sizeof(struct SensorConfig)); 18 | 19 | int ret = cfg_sensor_read(argv[1], &sc); 20 | 21 | if (ret < 0) 22 | { 23 | if (-1 == ret) 24 | { 25 | printf("I/O error, %d: %s\n", errno, strerror(errno)); 26 | } 27 | else 28 | { 29 | printf("Error %s(%d) at line %u, pos %u\n", cfg_proc_err_msg(ret), ret, cfg_proc_err_line_num(), cfg_proc_err_line_pos()); 30 | if (ret == CFG_PROC_WRONG_SECTION) 31 | { 32 | printf("Wrong section name [%s]\n", cfg_sensor_read_error_value()); 33 | } 34 | else if (ret == CFG_PROC_KEY_BAD) 35 | { 36 | printf("Wrong key \"%s\"\n", cfg_sensor_read_error_key()); 37 | } 38 | else if (ret == CFG_PROC_VALUE_BAD) 39 | { 40 | printf("Wrong value \"%s\" for %s\n", cfg_sensor_read_error_value(), cfg_sensor_read_error_key()); 41 | } 42 | } 43 | return ret; 44 | } 45 | 46 | cfg_sensor_pretty_print(&sc); 47 | 48 | return 0; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /aux/fonts/font.h: -------------------------------------------------------------------------------- 1 | #ifndef _FONT_H_ 2 | #define _FONT_H_ 3 | 4 | #include 5 | #include 6 | #include "utf8.h" 7 | 8 | // define the maximum size of margin top, margin bottom, margin left, margin width 9 | #define FONT_MARGIN_DATABIT_SIZE 6 // 4 10 | 11 | //================================================================= 12 | 13 | typedef struct 14 | { 15 | #if (CONFIG_FONT_FIXED_WIDTH_HEIGHT == 0u) 16 | // adapt size 17 | uint8_t width; 18 | uint8_t height; 19 | #endif 20 | 21 | #if (CONFIG_FONT_ENC >= 1u && CONFIG_FONT_ENC <= 3u) 22 | // calc_margin 23 | uint8_t margin_top :FONT_MARGIN_DATABIT_SIZE; 24 | uint8_t margin_bottom :FONT_MARGIN_DATABIT_SIZE; 25 | uint8_t margin_left :FONT_MARGIN_DATABIT_SIZE; 26 | uint8_t margin_right :FONT_MARGIN_DATABIT_SIZE; 27 | #endif 28 | 29 | uint16_t bmp_index; 30 | 31 | #if (CONFIG_FONT_ENC >= 2u && CONFIG_FONT_ENC <= 3u) 32 | uint8_t size; 33 | #endif 34 | }font_symbol_t; 35 | 36 | //================================================================= 37 | 38 | 39 | typedef bool (*fnt_lookup_fp)(utf8_t c, font_symbol_t *sym); 40 | 41 | typedef struct 42 | { 43 | #if (CONFIG_FONT_FIXED_WIDTH_HEIGHT > 0u) 44 | uint8_t width; 45 | uint8_t height; 46 | #else 47 | uint8_t default_width; 48 | uint8_t default_height; 49 | #endif 50 | 51 | const uint8_t *bmp_base; 52 | 53 | fnt_lookup_fp lookup; 54 | }font_t; 55 | 56 | //================================================================= 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /test/test_ao.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "mpi_sys.h" 5 | 6 | #include 7 | #include 8 | 9 | int stop_flag = 0; 10 | 11 | void action_on_sognal(int signum) 12 | { 13 | log_info("STOP"); 14 | stop_flag = 1; 15 | } 16 | 17 | int main(int argc, char** argv) 18 | { 19 | if (argc < 2) 20 | { 21 | log_error("./test_ao file_to_play.pcm"); 22 | return -1; 23 | 24 | } 25 | 26 | signal(SIGINT, action_on_sognal); 27 | 28 | int ret = 0; 29 | // int ret = sdk_init(0); 30 | // not to break VBs and working camera, we just init sdk 31 | // HI_MPI_SYS_Exit(); 32 | // int ret = HI_MPI_SYS_Init(); 33 | // if (ret < 0) 34 | // { 35 | // log_error("sdk_init() failed at %s: 0x%X", __sdk_last_call, ret); 36 | // return -1; 37 | // } 38 | 39 | log_warn("Warning! If segfaults here - broken libmpi.so/stat, please use patched version and libhisicompat."); 40 | ret = sdk_audio_init(0, PT_LPCM, 48000); 41 | if (ret < 0) 42 | { 43 | log_crit("init_sdk() failed at %s: 0x%X", __sdk_last_call, ret); 44 | return -1; 45 | } 46 | 47 | FILE* f = fopen(argv[1], "r"); 48 | if (f) 49 | { 50 | log_info("Now play %s!", argv[1]); 51 | sdk_audio_play(f, &stop_flag); 52 | fclose(f); 53 | } 54 | else 55 | { 56 | log_error("ERROR %d", errno); 57 | log_error("Error %d: %s", errno, strerror(errno)); 58 | } 59 | 60 | sdk_audio_done(); 61 | 62 | return 0; 63 | } 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /hitiny/hitiny_aio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2024 Alexander Pankov (pianisteg.mobile@gmail.com) 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. 16 | */ 17 | #ifndef __HITINY_AIO_H__ 18 | #define __HITINY_AIO_H__ 19 | 20 | #include "hi_comm_aio.h" 21 | 22 | int hitiny_init_acodec(AUDIO_SAMPLE_RATE_E enSample, HI_BOOL bMicIn); 23 | 24 | int hitiny_MPI_AO_Init(); 25 | void hitiny_MPI_AO_Done(); 26 | 27 | int hitiny_MPI_AO_SetPubAttr(AUDIO_DEV AudioDevId, const AIO_ATTR_S *pstAttr); 28 | int hitiny_MPI_AO_GetPubAttr(AUDIO_DEV AudioDevId, AIO_ATTR_S *pstAttr); 29 | 30 | int hitiny_MPI_AO_Enable(AUDIO_DEV AudioDevId); 31 | int hitiny_MPI_AO_Disable(AUDIO_DEV AudioDevId); 32 | 33 | int hitiny_MPI_AO_EnableChn(AUDIO_DEV AudioDevId, AO_CHN AoChn); 34 | int hitiny_MPI_AO_DisableChn(AUDIO_DEV AudioDevId, AO_CHN AoChn); 35 | 36 | int hitiny_MPI_AO_GetFd(AUDIO_DEV AoDevId, AO_CHN AoChn); 37 | int hitiny_MPI_AO_SendFrame(AUDIO_DEV AudioDevId, AO_CHN AoChn, const AUDIO_FRAME_S *pstData, HI_BOOL bBlock); 38 | 39 | #endif // __HITINY_AIO_H__ 40 | 41 | -------------------------------------------------------------------------------- /tinydraw/image.c: -------------------------------------------------------------------------------- 1 | #include "image.h" 2 | #include 3 | #include 4 | 5 | #define JUNK_CTXBBP 2 6 | 7 | void tinydraw_renderer_ctx_init(tinydraw_renderer_ctx_t* ctx, uint32_t width, uint32_t height, uint8_t _bits_per_px) 8 | { 9 | memset(ctx, 0, sizeof(tinydraw_renderer_ctx_t)); 10 | 11 | ctx->width = width; 12 | ctx->height = height; 13 | 14 | ctx->bits_per_px = _bits_per_px; 15 | ctx->sz_buffer = height * width * JUNK_CTXBBP; 16 | ctx->buffer = (uint8_t*)malloc(ctx->sz_buffer); 17 | 18 | ctx->color_bg = DEFALT_BG_COLOR; 19 | ctx->color_brush = DEFALT_BRUSH_COLOR; 20 | 21 | ctx->font_draw_colors[0] = BLACK_COLOR; 22 | ctx->font_draw_colors[1] = DARK_GREY_COLOR; 23 | ctx->font_draw_colors[2] = LIGHT_GREY_COLOR; 24 | ctx->font_draw_colors[3] = WHITE_COLOR; 25 | 26 | tinydraw_renderer_clear_screen(ctx); 27 | } 28 | 29 | void tinydraw_renderer_ctx_done(tinydraw_renderer_ctx_t* ctx) 30 | { 31 | free(ctx->buffer); 32 | ctx->buffer = 0; 33 | } 34 | 35 | void tinydraw_renderer_clear_screen(tinydraw_renderer_ctx_t* ctx) 36 | { 37 | unsigned total_px_cnt = ctx->width * ctx->height * JUNK_CTXBBP; 38 | 39 | for (unsigned i = 0; i < total_px_cnt; i += JUNK_CTXBBP) 40 | { 41 | *(uint16_t*)(&ctx->buffer[i]) = ctx->color_bg; 42 | } 43 | } 44 | 45 | void tinydraw_renderer_draw_pixel(tinydraw_renderer_ctx_t* ctx, uint16_t x, uint16_t y, tinydraw_color_t color) 46 | { 47 | if (x >= ctx->width) return; 48 | if (y >= ctx->height) return; 49 | 50 | unsigned ptr = 2 * (y * ctx->width + x); 51 | *(uint16_t*)(&ctx->buffer[ptr]) = color; 52 | } 53 | 54 | 55 | -------------------------------------------------------------------------------- /evcurl/evcurl.h: -------------------------------------------------------------------------------- 1 | #ifndef __evcurl_h__ 2 | #define __evcurl_h__ 3 | 4 | #include 5 | #include 6 | 7 | 8 | typedef struct evcurl_processor_s 9 | { 10 | struct ev_loop *loop; 11 | struct ev_timer timer_event; 12 | CURLM *multi; 13 | int still_running; 14 | } evcurl_processor_t; 15 | 16 | evcurl_processor_t *evcurl_create(struct ev_loop* loop); 17 | void evcurl_destroy(evcurl_processor_t* __evcurl_pi); 18 | 19 | 20 | typedef struct evcurl_req_result_s 21 | { 22 | CURLcode result; 23 | const char* effective_url; 24 | long response_code; 25 | const char* content_type; 26 | 27 | void* body; 28 | size_t sz_body; 29 | } evcurl_req_result_t; 30 | 31 | typedef void (*evcurl_req_done_cb)(evcurl_req_result_t* res, void* src_req_data); 32 | 33 | CURLMcode evcurl_new_http_GET(evcurl_processor_t *mp, char *url, evcurl_req_done_cb _finish_cb); 34 | 35 | typedef struct evcurl_upload_req_s 36 | { 37 | long timeout; 38 | long connect_timeout; 39 | 40 | const char* url; 41 | const char* username; 42 | const char* password; 43 | 44 | void* buf; 45 | size_t sz_buf; 46 | void* ptr; 47 | } evcurl_upload_req_t; 48 | 49 | CURLMcode evcurl_new_UPLOAD(evcurl_processor_t *mp, evcurl_upload_req_t* req, evcurl_req_done_cb _finish_cb); 50 | 51 | typedef struct evcurl_upload_chunked_req_s 52 | { 53 | long timeout; 54 | long connect_timeout; 55 | 56 | const char* url; 57 | const char* username; 58 | const char* password; 59 | 60 | curl_read_callback read_cb; 61 | } evcurl_upload_chunked_req_t; 62 | 63 | CURLMcode evcurl_new_UPLOAD_chunked(evcurl_processor_t *mp, evcurl_upload_chunked_req_t* req, evcurl_req_done_cb _finish_cb, CURL **easy_handler); 64 | 65 | #endif //__evcurl_h__ 66 | 67 | -------------------------------------------------------------------------------- /devices/BLK18E_0042/reverse/ipctool.txt: -------------------------------------------------------------------------------- 1 | # ./ipctool-2024-03-26 2 | 3 | --- 4 | chip: 5 | vendor: HiSilicon 6 | model: 3518EV100 7 | board: 8 | vendor: Xiongmai 9 | param: HI3518E_50H10L_S39 10 | cloudId: e59fe45eaa5ca3f8 11 | possible-IR-cut-GPIO: 13,26,38,39,41,43,75 12 | ethernet: 13 | mac: "00:12:16:d0:12:2b" 14 | u-mdio-phyaddr: 1 15 | phy-id: 0x02430c54 16 | d-mdio-phyaddr: 0 17 | phy-mode: mii 18 | rom: 19 | - type: nor 20 | block: 64K 21 | partitions: 22 | - name: boot 23 | size: 0x40000 24 | sha1: 741a6187 25 | contains: 26 | - name: xmcrypto 27 | offset: 0x1fc00 28 | - name: uboot-env 29 | offset: 0x30000 30 | - name: romfs 31 | size: 0x370000 32 | path: /,cramfs 33 | sha1: aae3bca9 34 | - name: user 35 | size: 0x280000 36 | path: /usr,squashfs 37 | sha1: 68c7d211 38 | - name: web 39 | size: 0x140000 40 | path: /mnt/web,squashfs 41 | sha1: 00ed8097 42 | - name: custom 43 | size: 0x40000 44 | path: /mnt/custom,cramfs 45 | sha1: 2035f55c 46 | - name: mtd 47 | size: 0x50000 48 | path: /mnt/mtd,jffs2,rw 49 | size: 8M 50 | addr-mode: 3-byte 51 | ram: 52 | total: 64M 53 | media: 20M 54 | firmware: 55 | u-boot: "2010.06 (Apr 07 2012 - 17:11:2)" 56 | kernel: "3.0.8 (Mon Jan 18 14:29:26 CST 2016)" 57 | toolchain: gcc version 4.4.1 (Hisilicon_v100(gcc4.4-290+uclibc_0.9.32.1+eabi+linuxpthread)) 58 | libc: uClibc 0.9.32.1 59 | sdk: "Hi3518_MPP_V1.0.A.0 (Apr 1 2015, 19:36:33)" 60 | main-app: /usr/bin/Sofia 61 | sensors: 62 | - vendor: Silicon Optronics 63 | model: JXH42 64 | control: 65 | bus: 0 66 | type: i2c 67 | addr: 0x60 68 | data: 69 | type: DC 70 | clock: 24MHz 71 | 72 | -------------------------------------------------------------------------------- /cfg/compat.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPAT_H 2 | #define COMPAT_H 3 | 4 | #if HISILICON_SDK_CODE == 0x3518 5 | #define HISILICON_SDK_GEN 1 6 | #elif HISILICON_SDK_CODE == 0x3518E200 7 | #define HISILICON_SDK_GEN 2 8 | #elif HISILICON_SDK_CODE == 0x3516A 9 | #define HISILICON_SDK_GEN 2 10 | #elif HISILICON_SDK_CODE == 0x3516C300 11 | #define HISILICON_SDK_GEN 3 12 | #elif HISILICON_SDK_CODE == 0x3516E200 13 | #define HISILICON_SDK_GEN 4 14 | #elif HISILICON_SDK_CODE == 0x3516C500 15 | #define HISILICON_SDK_GEN 4 16 | #elif HISILICON_SDK_CODE == 0x7205200 17 | #define HISILICON_SDK_GEN 4 18 | #endif 19 | 20 | #pragma GCC diagnostic push 21 | #pragma GCC diagnostic ignored "-Wsign-compare" 22 | #include 23 | #pragma GCC diagnostic pop 24 | 25 | #ifndef ALIGN_UP 26 | #define ALIGN_UP(x, a) ((((x) + ((a)-1)) / a) * a) 27 | #endif 28 | 29 | #include 30 | #if HISILICON_SDK_GEN >= 2 31 | #include 32 | #endif 33 | #include 34 | #if HISILICON_SDK_GEN <= 3 35 | #include 36 | #endif 37 | #if HISILICON_SDK_GEN == 4 38 | #include 39 | #include 40 | #include 41 | #endif 42 | 43 | #if HISILICON_SDK_GEN == 2 || HISILICON_SDK_GEN == 3 44 | typedef raw_data_type_e data_type_t; 45 | 46 | typedef wdr_mode_e wdr_mode_t; 47 | typedef lvds_sync_mode_e lvds_sync_mode_t; 48 | typedef lvds_bit_endian lvds_bit_endian_t; 49 | 50 | typedef BT656_FIXCODE_E VI_BT656_FIXCODE_E; 51 | typedef BT656_FIELD_POLAR_E VI_BT656_FIELD_POLAR_E; 52 | #endif 53 | 54 | #if HISILICON_SDK_GEN <= 2 55 | #define MPEG_ATTR stAttrMjpeg 56 | #define JPEG_ATTR stAttrJpeg 57 | #elif HISILICON_SDK_GEN == 3 58 | #define MPEG_ATTR stAttrMjpege 59 | #define JPEG_ATTR stAttrJpege 60 | #endif 61 | 62 | #define MIPI_DEV "/dev/hi_mipi" 63 | 64 | #endif /* COMPAT_H */ 65 | -------------------------------------------------------------------------------- /doc/mmz.txt: -------------------------------------------------------------------------------- 1 | MMZ (Media Memory Zone) 2 | ======================= 3 | 4 | Часть памяти, которая используется для всех аппаратных сопроцессоров. 5 | 6 | Информация по состоянию: `cat /proc/media-mem` 7 | 8 | Объём памяти задаётся при загрузке ядра, bootargs параметр mem — что ядру ОС, что медиа процессорам. 9 | 10 | Контролируется драйвером `mmz.ko`. 11 | 12 | https://github.com/caps-liu/hisi-driverlibs/blob/2fb5ac209eafb7f7e95ddc92b5b2aac35cbd1490/source/common/drv/include/drv_mmz_ioctl.h 13 | 14 | #define HIL_MMZ_NAME_LEN 32 15 | #define HIL_MMB_NAME_LEN 16 16 | 17 | struct mmb_info { 18 | unsigned long phys_addr; /* phys-memory address */ 19 | unsigned long align; /* if you need your phys-memory have special align size */ 20 | unsigned long size; /* length of memory you need, in bytes */ 21 | unsigned int order; 22 | 23 | void *mapped; /* userspace mapped ptr */ 24 | 25 | union { 26 | struct { 27 | unsigned long prot :8; /* PROT_READ or PROT_WRITE */ 28 | unsigned long flags :12;/* MAP_SHARED or MAP_PRIVATE */ 29 | 30 | #ifdef __KERNEL__ 31 | unsigned long reserved :8; /* reserved, do not use */ 32 | unsigned long delayed_free :1; 33 | unsigned long map_cached :1; 34 | #ifdef MMZ_V2_SUPPORT 35 | unsigned long mmb_type :2; /*0: not share, 1 :share and in current program list , 2: share and in share list*/ 36 | #endif 37 | #endif 38 | }; 39 | unsigned long w32_stuf; 40 | }; 41 | 42 | char mmb_name[HIL_MMB_NAME_LEN]; 43 | char mmz_name[HIL_MMZ_NAME_LEN]; 44 | unsigned long gfp; /* reserved, do set to 0 */ 45 | pid_t pid; 46 | #ifdef __KERNEL__ 47 | int map_ref; 48 | int mmb_ref; 49 | 50 | struct list_head list; 51 | hil_mmb_t *mmb; 52 | #ifdef MMZ_V2_SUPPORT 53 | struct list_head share_list; 54 | #endif 55 | #endif 56 | }; 57 | /*lint -restore */ 58 | 59 | -------------------------------------------------------------------------------- /tinydraw/image.h: -------------------------------------------------------------------------------- 1 | #ifndef __TINYDRAW_IMAGE_H__ 2 | #define __TINYDRAW_IMAGE_H__ 3 | 4 | #include 5 | 6 | typedef uint16_t tinydraw_color_t; 7 | 8 | #define RGB888_TO_RGB555(r,g,b) (((((uint16_t)r) & 0b11111000) << 7) | ((((uint16_t)g) & 0b11111000) << 2) | (((uint16_t)b) >> 3)) 9 | 10 | #define BLACK_COLOR 0x0000 11 | #define WHITE_COLOR 0xFFFF 12 | #define RED_COLOR 0xF800 13 | #define GREEN_COLOR 0x87E0 14 | #define BLUE_COLOR 0x801F 15 | #define CYAN_COLOR 0x87FF 16 | #define YELLOW_COLOR 0xFFE0 17 | #define PURPLE_COLOR 0xF81F 18 | #define LIGHT_GREY_COLOR (0x8000 | RGB888_TO_RGB555(168, 168, 168)) 19 | #define DARK_GREY_COLOR (0x8000 | RGB888_TO_RGB555(96, 96, 96)) 20 | 21 | 22 | #define DEFALT_BG_COLOR BLACK_COLOR 23 | #define DEFALT_BRUSH_COLOR WHITE_COLOR 24 | 25 | typedef struct { 26 | uint32_t x; 27 | uint32_t y; 28 | } tinydraw_point_t; 29 | 30 | typedef struct { 31 | uint32_t x0; 32 | uint32_t y0; 33 | uint32_t x1; 34 | uint32_t y1; 35 | } tinydraw_rect_t; 36 | 37 | 38 | typedef struct { 39 | uint32_t width; 40 | uint32_t height; 41 | uint8_t *buffer; 42 | unsigned sz_buffer; 43 | uint8_t bits_per_px; 44 | tinydraw_rect_t screen_bond; 45 | tinydraw_point_t cur; 46 | 47 | tinydraw_color_t color_bg; 48 | tinydraw_color_t color_brush; 49 | 50 | tinydraw_color_t font_draw_colors[4]; 51 | } tinydraw_renderer_ctx_t; 52 | 53 | void tinydraw_renderer_ctx_init(tinydraw_renderer_ctx_t* ctx, uint32_t width, uint32_t height, uint8_t bits_per_px); 54 | void tinydraw_renderer_ctx_done(tinydraw_renderer_ctx_t* ctx); 55 | 56 | void tinydraw_renderer_save_bmp(tinydraw_renderer_ctx_t* ctx, const char* filename); 57 | 58 | void tinydraw_renderer_clear_screen(tinydraw_renderer_ctx_t* ctx); 59 | void tinydraw_renderer_draw_pixel(tinydraw_renderer_ctx_t* ctx, uint16_t x, uint16_t y, tinydraw_color_t color); 60 | 61 | #endif // __TINYDRAW_IMAGE_H__ 62 | 63 | -------------------------------------------------------------------------------- /cmake/Modules/get_hisisdk_ver.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | import os 5 | import re 6 | 7 | 8 | def make_hex(string): 9 | return re.sub(r'[^\dA-Fa-f]', '', string) 10 | 11 | 12 | def make_good_name(manufacturer, hexcode): 13 | return (manufacturer + hexcode[:4] + 14 | "V" + hexcode[4:]).title() 15 | 16 | 17 | # strings ./mpp/ko/hi3516cv300_sys.ko|grep "\[SYS\] Version: " 18 | def find_sdk_version(filename, match): 19 | manufacturer = match[0][0] 20 | if manufacturer == 'hi': 21 | r = br'\[(?:SYS|ISP)\]\sVersion: \[(.+)(?:_MPP)_V(\d+)\.(\d+)\.([\d\w]+)\.(\d+) (.+ Release)*\].+\[(.+)\]' 22 | elif manufacturer == 'gk': 23 | r = br'\[ISP\]\sVersion: \[()ISP_V(\d+)\.(\d+)\.([\d\w]+)\.(\d+) (.+ Release)*\].+\[(.+)\]' 24 | else: 25 | return False 26 | pattern = re.compile(r) 27 | with open(filename, "rb") as f: 28 | ret = pattern.findall(f.read()) 29 | if ret: 30 | matches = [x.decode() for x in ret[0]] 31 | hexcode = make_hex(matches[0]) 32 | if hexcode == "": 33 | hexcode = make_hex(os.path.basename(filename)) 34 | matches[0] = make_good_name(manufacturer, hexcode) 35 | print(hexcode, ";".join(matches), sep=';', 36 | end='') 37 | return True 38 | return False 39 | 40 | 41 | # traverse root directory, and list directories as dirs and files as files 42 | def find_sys_ko(path): 43 | pattern = re.compile(r"(\w\w)[0-9a-z]+_(sys|isp).ko") 44 | for root, dirs, files in os.walk(path): 45 | path = root.split(os.sep) 46 | for file in files: 47 | match = pattern.findall(file) 48 | if match: 49 | if find_sdk_version(os.path.join(root, file), match): 50 | return 51 | 52 | 53 | def main(): 54 | if len(sys.argv) != 2: 55 | root_dir = os.getcwd() 56 | else: 57 | root_dir = sys.argv[1] 58 | find_sys_ko(root_dir) 59 | 60 | 61 | if __name__ == '__main__': 62 | main() 63 | -------------------------------------------------------------------------------- /aux/fonts/utf8.c: -------------------------------------------------------------------------------- 1 | /* Extract some utf-8 functions from https://github.com/vigna/ne/blob/master/src/utf8.c */ 2 | 3 | /* UTF-8 support. 4 | Copyright (C) 1993-1998 Sebastiano Vigna 5 | Copyright (C) 1999-2021 Todd M. Lewis and Sebastiano Vigna 6 | This file is part of ne, the nice editor. 7 | This library is free software; you can redistribute it and/or modify it 8 | under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | This library is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | for more details. 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, see . */ 17 | 18 | #include "utf8.h" 19 | 20 | 21 | /* Returns the length of a bytes sequence encoding the given character. */ 22 | uint8_t utf8_charlen(utf8_t c) { 23 | if (c < 0x80) return 1; 24 | if (c < 0x800) return 2; 25 | if (c < 0x10000) return 3; 26 | if (c < 0x200000) return 4; 27 | if (c < 0x4000000) return 5; 28 | return 6; 29 | } 30 | 31 | /* Return the Unicode characters represented by the given string, or -1 if an error occurs. */ 32 | 33 | utf8_t utf8_getchar(const char * const ss) { 34 | const uint8_t * const s = (const uint8_t *)ss; 35 | if (s[0] < 0x80) return s[0]; 36 | if (s[0] < 0xC0) return -1; 37 | if (s[0] < 0xE0) return (s[0] & 0x1F) << 6 | s[1] & 0x3F; 38 | if (s[0] < 0xF0) return (s[0] & 0xF) << 12 | (s[1] & 0x3F) << 6 | (s[2] & 0x3F); 39 | if (s[0] < 0xF8) return (s[0] & 0x7) << 18 | (s[1] & 0x3F) << 12 | (s[2] & 0x3F) << 6 | (s[3] & 0x3F); 40 | if (s[0] < 0xFC) return (s[0] & 0x3) << 24 | (s[1] & 0x3F) << 18 | (s[2] & 0x3F) << 12 | (s[3] & 0x3F) << 6 | (s[4] & 0x3F); 41 | return (s[0] & 0x1) << 30 | (s[1] & 0x3F) << 24 | (s[2] & 0x3F) << 18 | (s[3] & 0x3F) << 12 | (s[4] & 0x3F) << 6 | (s[5] & 0x3F); 42 | } 43 | -------------------------------------------------------------------------------- /test/test_tinydraw_2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char** argv) 8 | { 9 | tinydraw_renderer_ctx_t td_ctx; 10 | tinydraw_renderer_ctx_init(&td_ctx, 1100, 240, 16); 11 | 12 | tinydraw_renderer_draw_string(&td_ctx, 0, 0, &tinydraw_font_monaco32, "The quick brown fox jumps over the lazy dog."); 13 | 14 | char buf[64]; 15 | struct tm tmloc; 16 | struct timeval tv; 17 | gettimeofday(&tv, NULL); 18 | localtime_r(&tv.tv_sec, &tmloc); 19 | snprintf(buf, 64, "%04u-%02u-%02u %02u:%02u:%02u", tmloc.tm_year + 1900, tmloc.tm_mon + 1, tmloc.tm_mday, tmloc.tm_hour, tmloc.tm_min, tmloc.tm_sec); 20 | 21 | tinydraw_renderer_draw_string(&td_ctx, 0, 200, &tinydraw_font_monaco32, buf); 22 | tinydraw_renderer_draw_string(&td_ctx, 0, 120, &tinydraw_font_monaco32, "Cozy sphinx waves quart jug of bad milk."); 23 | 24 | td_ctx.font_draw_colors[0] = BLACK_COLOR; 25 | td_ctx.font_draw_colors[1] = (RED_COLOR / 3) & RED_COLOR; 26 | td_ctx.font_draw_colors[2] = (RED_COLOR / 2) & RED_COLOR; 27 | td_ctx.font_draw_colors[3] = RED_COLOR; 28 | tinydraw_renderer_draw_string(&td_ctx, 0, 40, &tinydraw_font_monaco32, "Crazy Fredrick bought many very exquisite opal jewels."); 29 | 30 | td_ctx.font_draw_colors[0] = BLUE_COLOR; 31 | td_ctx.font_draw_colors[1] = (BLUE_COLOR / 2) & BLUE_COLOR; 32 | td_ctx.font_draw_colors[2] = (BLUE_COLOR / 4) & BLUE_COLOR; 33 | td_ctx.font_draw_colors[3] = BLACK_COLOR; 34 | tinydraw_renderer_draw_string(&td_ctx, 0, 80, &tinydraw_font_monaco32, "The jay, pig, fox, zebra and my wolves quack!"); 35 | 36 | td_ctx.font_draw_colors[0] = DARK_GREY_COLOR; 37 | td_ctx.font_draw_colors[1] = WHITE_COLOR;//(YELLOW_COLOR / 4) & YELLOW_COLOR; 38 | td_ctx.font_draw_colors[2] = WHITE_COLOR;//(YELLOW_COLOR / 2) & YELLOW_COLOR; 39 | td_ctx.font_draw_colors[3] = WHITE_COLOR;//YELLOW_COLOR; 40 | tinydraw_renderer_draw_string(&td_ctx, 0, 160, &tinydraw_font_monaco32, "(10 + 9 + ... + 1) = (10 + 1) * (10/2) = 55"); 41 | 42 | tinydraw_renderer_save_bmp(&td_ctx, "test.bmp"); 43 | tinydraw_renderer_ctx_done(&td_ctx); 44 | 45 | return 0; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /platform/sdk_sensor.c: -------------------------------------------------------------------------------- 1 | #include "sdk.h" 2 | #include 3 | #include 4 | #include 5 | 6 | int (*sensor_register_callback_fn)(void); 7 | int (*sensor_unregister_callback_fn)(void); 8 | #if HISILICON_SDK_GEN < 2 9 | void (*sensor_init_fn)(void); 10 | #endif 11 | void *libsns_so = NULL; 12 | 13 | static int tryLoadLibrary(const char *path) { 14 | log_info("try to load: %s", path); 15 | libsns_so = dlopen(path, RTLD_NOW | RTLD_GLOBAL); 16 | log_info("libsns_so 0x%016" PRIXPTR, (uintptr_t)libsns_so); 17 | if (libsns_so == NULL) { 18 | log_error("dlopen \"%s\" error: %s", path, dlerror()); 19 | return 0; 20 | } 21 | return 1; 22 | } 23 | 24 | int LoadSensorLibrary(const char *libsns_name) { 25 | char path[250]; 26 | sprintf(path, "%s", libsns_name); 27 | if (tryLoadLibrary(path) != 1) { 28 | sprintf(path, "./%s", libsns_name); 29 | if (tryLoadLibrary(path) != 1) { 30 | sprintf(path, "/usr/lib/%s", libsns_name); 31 | if (tryLoadLibrary(path) != 1) { 32 | return 0; 33 | } 34 | } 35 | } 36 | 37 | #if HISILICON_SDK_GEN < 2 38 | sensor_init_fn = dlsym(libsns_so, "sensor_init"); 39 | #endif 40 | 41 | sensor_register_callback_fn = dlsym(libsns_so, "sensor_register_callback"); 42 | sensor_unregister_callback_fn = 43 | dlsym(libsns_so, "sensor_unregister_callback"); 44 | return 1; 45 | } 46 | 47 | int sensor_register_callback(void) { return sensor_register_callback_fn(); } 48 | int sensor_unregister_callback(void) { return sensor_unregister_callback_fn(); } 49 | 50 | int sdk_sensor_init(const struct SensorConfig* sc) 51 | { 52 | if (!LoadSensorLibrary(sc->dll_file)) 53 | { 54 | log_error("Can't load %s", sc->dll_file); 55 | return -1; 56 | } 57 | 58 | #if HISILICON_SDK_GEN < 2 59 | sensor_init_fn(); 60 | #endif 61 | 62 | int s32Ret = sensor_register_callback(); 63 | if (HI_SUCCESS != s32Ret) { 64 | log_error("sensor_register_callback() failed with %#x!", s32Ret); 65 | return -1; 66 | } 67 | } 68 | 69 | void sdk_sensor_done() 70 | { 71 | sensor_unregister_callback(); 72 | dlclose(libsns_so); 73 | libsns_so = NULL; 74 | } 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /test/test_vi_ext.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int stop_flag = 0; 9 | 10 | void action_on_signal(int signum) 11 | { 12 | log_info("STOP"); 13 | stop_flag = 1; 14 | } 15 | 16 | int create_vi_ext_chnl(unsigned width, unsigned height, unsigned pix_format, int src_frame_rate, int frame_rate) 17 | { 18 | log_info("starting ext vi chnl 1: %ux%u, PixFormat = %s(%d), src_fr/fr = %d/%d", width, height, cfg_sensor_vals_vichn_pixel_format[pix_format], pix_format, src_frame_rate, frame_rate); 19 | 20 | VI_EXT_CHN_ATTR_S stViExtChnAttr; 21 | stViExtChnAttr.s32BindChn = 0; 22 | stViExtChnAttr.stDestSize.u32Width = width; 23 | stViExtChnAttr.stDestSize.u32Height = height; 24 | stViExtChnAttr.s32SrcFrameRate = src_frame_rate; 25 | stViExtChnAttr.s32FrameRate = frame_rate; 26 | stViExtChnAttr.enPixFormat = pix_format; 27 | 28 | int s32Ret; 29 | s32Ret = hitiny_MPI_VI_SetExtChnAttr(1, &stViExtChnAttr); 30 | if (HI_SUCCESS != s32Ret) { 31 | log_error("HI_MPI_VI_SetExtChnAttr failed with %#x!", s32Ret); 32 | return s32Ret; 33 | } 34 | 35 | s32Ret = hitiny_MPI_VI_EnableChn(1); 36 | if (HI_SUCCESS != s32Ret) { 37 | log_error("HI_MPI_VI_SetExtChnAttr failed with %#x!", s32Ret); 38 | return s32Ret; 39 | } 40 | 41 | return HI_SUCCESS; 42 | } 43 | 44 | int main(int argc, char** argv) 45 | { 46 | hitiny_MPI_VI_Init(); 47 | 48 | signal(SIGINT, action_on_signal); 49 | signal(SIGTERM, action_on_signal); 50 | 51 | if (argc < 3) 52 | { 53 | fprintf(stderr, "Usage: %s width height\n", argv[0]); 54 | return -1; 55 | } 56 | 57 | int ret = create_vi_ext_chnl(atoi(argv[1]), atoi(argv[2]), 19, -1, -1); 58 | if (ret != 0) 59 | { 60 | fprintf(stderr, "Error, can't emable chnl\n"); 61 | return -1; 62 | } 63 | 64 | for (int i = 10; i && !stop_flag; --i) 65 | { 66 | fprintf(stderr, "waiting for %d sec\n", i); 67 | sleep(1); 68 | } 69 | 70 | ret = hitiny_MPI_VI_DisableChn(1); 71 | printf("Disable cnhl: %#x\n", ret); 72 | 73 | hitiny_MPI_VI_Done(); 74 | 75 | return 0; 76 | } 77 | 78 | -------------------------------------------------------------------------------- /tinydraw/save_bmp.c: -------------------------------------------------------------------------------- 1 | #include "image.h" 2 | #include 3 | #include 4 | 5 | #define TINYDRAW_BMP_planes 1 6 | #define TINYDRAW_BMP_compression 0 7 | #define TINYDRAW_BMP_xpixelpermeter 0x130B /* 2835 , 72 DPI */ 8 | #define TINYDRAW_BMP_ypixelpermeter 0x130B /* 2835 , 72 DPI */ 9 | 10 | #pragma pack(push,1) 11 | typedef struct tinydraw_bmp_fileheader_s { 12 | uint8_t signature[2]; 13 | uint32_t filesize; 14 | uint32_t reserved; 15 | uint32_t fileoffset_to_pixelarray; 16 | } tinydraw_bmp_fileheader_t; 17 | 18 | typedef struct tinydraw_bmp_bitmapinfoheader_s { 19 | uint32_t dibheadersize; 20 | uint32_t width; 21 | uint32_t height; 22 | uint16_t planes; 23 | uint16_t bitsperpixel; 24 | uint32_t compression; 25 | uint32_t imagesize; 26 | uint32_t ypixelpermeter; 27 | uint32_t xpixelpermeter; 28 | uint32_t numcolorspallette; 29 | uint32_t mostimpcolor; 30 | } tinydraw_bmp_bitmapinfoheader_t; 31 | 32 | typedef struct { 33 | tinydraw_bmp_fileheader_t fileheader; 34 | tinydraw_bmp_bitmapinfoheader_t bitmapinfoheader; 35 | } tinydraw_bmp_t; 36 | #pragma pack(pop) 37 | 38 | 39 | void tinydraw_renderer_save_bmp(tinydraw_renderer_ctx_t* ctx, const char* filename) 40 | { 41 | FILE *fp = fopen(filename, "wb"); 42 | 43 | tinydraw_bmp_t bmp; 44 | memset(&bmp, 0, sizeof(tinydraw_bmp_t)); 45 | 46 | memcpy(bmp.fileheader.signature, "BM", 2); // fi.bfType = 0x4D42; 47 | 48 | bmp.fileheader.filesize = ctx->sz_buffer + sizeof(tinydraw_bmp_t); 49 | bmp.fileheader.fileoffset_to_pixelarray = sizeof(tinydraw_bmp_t); 50 | 51 | bmp.bitmapinfoheader.dibheadersize = sizeof(tinydraw_bmp_bitmapinfoheader_t); 52 | bmp.bitmapinfoheader.width = ctx->width; 53 | bmp.bitmapinfoheader.height = -ctx->height; 54 | bmp.bitmapinfoheader.planes = TINYDRAW_BMP_planes; 55 | bmp.bitmapinfoheader.bitsperpixel = ctx->bits_per_px; 56 | bmp.bitmapinfoheader.compression = TINYDRAW_BMP_compression; 57 | bmp.bitmapinfoheader.imagesize = ctx->sz_buffer; 58 | bmp.bitmapinfoheader.ypixelpermeter = TINYDRAW_BMP_ypixelpermeter; 59 | bmp.bitmapinfoheader.xpixelpermeter = TINYDRAW_BMP_xpixelpermeter; 60 | bmp.bitmapinfoheader.numcolorspallette = 32768; 61 | 62 | fwrite(&bmp, 1, sizeof(tinydraw_bmp_t), fp); 63 | fwrite(ctx->buffer, 1, ctx->sz_buffer, fp); 64 | 65 | fclose(fp); 66 | } 67 | 68 | -------------------------------------------------------------------------------- /hitiny/hitiny_ive.c: -------------------------------------------------------------------------------- 1 | #include "hitiny_ive.h" 2 | #include 3 | 4 | struct __IVE_Query_param_s 5 | { 6 | IVE_HANDLE ive_handle; 7 | HI_BOOL block; 8 | HI_BOOL finish; 9 | }; 10 | 11 | int hitiny_MPI_IVE_Query(IVE_HANDLE IveHandle, HI_BOOL *pbFinish, HI_BOOL bBlock) 12 | { 13 | int fd = hitiny_ive_fd(); 14 | if (fd < 0) return 0xa01d8010; 15 | 16 | struct __IVE_Query_param_s param; 17 | param.ive_handle = IveHandle; 18 | param.block = bBlock; 19 | param.finish = HI_FALSE; 20 | 21 | int result = ioctl(fd, 0xc00c460e, ¶m); 22 | if (result) return result; 23 | 24 | if (pbFinish) *pbFinish = param.finish; 25 | 26 | return 0; 27 | } 28 | 29 | struct __IVE_Hist_param_s 30 | { 31 | IVE_HANDLE ive_handle; 32 | IVE_SRC_INFO_S src; 33 | IVE_MEM_INFO_S dest; 34 | HI_BOOL instant; 35 | }; 36 | 37 | int hitiny_MPI_IVE_HIST(IVE_HANDLE *pIveHandle, IVE_SRC_INFO_S *pstSrc, IVE_MEM_INFO_S *pstDst, HI_BOOL bInstant) 38 | { 39 | if (!pIveHandle || !pstSrc || !pstDst) return 0xa01d8006; 40 | 41 | int fd = hitiny_ive_fd(); 42 | if (fd < 0) return 0xa01d8010; 43 | 44 | struct __IVE_Hist_param_s param; 45 | param.ive_handle = 0; 46 | param.src = *pstSrc; 47 | param.dest = *pstDst; 48 | param.instant = bInstant; 49 | 50 | int result = ioctl(fd, 0xc024460d, ¶m); 51 | if (result) return result; 52 | 53 | *pIveHandle = param.ive_handle; 54 | 55 | return 0; 56 | } 57 | 58 | struct __IVE_Filter_param_s 59 | { 60 | IVE_HANDLE ive_handle; 61 | IVE_SRC_INFO_S src; 62 | IVE_MEM_INFO_S dest; 63 | HI_BOOL instant; 64 | IVE_FILTER_CTRL_S filter; 65 | }; 66 | 67 | int hitiny_MPI_IVE_FILTER(IVE_HANDLE *pIveHandle, IVE_SRC_INFO_S *pstSrc, IVE_MEM_INFO_S *pstDst, IVE_FILTER_CTRL_S *pstFilterCtrl, HI_BOOL bInstant) 68 | { 69 | if (!pIveHandle || !pstSrc || !pstDst || !pstFilterCtrl) return 0xa01d8006; 70 | 71 | int fd = hitiny_ive_fd(); 72 | if (fd < 0) return 0xa01d8010; 73 | 74 | struct __IVE_Filter_param_s param; 75 | param.ive_handle = 0; 76 | param.src = *pstSrc; 77 | param.dest = *pstDst; 78 | param.instant = bInstant; 79 | param.filter = *pstFilterCtrl; 80 | 81 | int result = ioctl(fd, 0xc0304601, ¶m); 82 | if (result) return result; 83 | 84 | *pIveHandle = param.ive_handle; 85 | 86 | return 0; 87 | } 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /hitiny/hitiny_aio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2024 Alexander Pankov (pianisteg.mobile@gmail.com) 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. 16 | */ 17 | #include "hitiny_sys.h" 18 | #include "hitiny_aio.h" 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "acodec.h" 28 | 29 | int hitiny_init_acodec(AUDIO_SAMPLE_RATE_E enSample, HI_BOOL bMicIn) 30 | { 31 | int fd_acodec = -1; 32 | 33 | fd_acodec = hitiny_open_dev("/dev/acodec"); 34 | if (fd_acodec < 0) return fd_acodec; 35 | 36 | int ret = 0; 37 | ret = ioctl(fd_acodec, ACODEC_SOFT_RESET_CTRL); 38 | if (0 != ret) 39 | { 40 | log_error("ERROR in hitiny_init_acodec/ACODEC_SOFT_RESET_CTRL: %d (%s)\n", errno, strerror(errno)); 41 | close(fd_acodec); 42 | return ret; 43 | } 44 | 45 | unsigned int i2s_fs_sel = 0; 46 | switch (enSample) 47 | { 48 | case AUDIO_SAMPLE_RATE_8000: 49 | case AUDIO_SAMPLE_RATE_11025: 50 | case AUDIO_SAMPLE_RATE_12000: 51 | i2s_fs_sel = 0x18; 52 | break; 53 | 54 | case AUDIO_SAMPLE_RATE_16000: 55 | case AUDIO_SAMPLE_RATE_22050: 56 | case AUDIO_SAMPLE_RATE_24000: 57 | i2s_fs_sel = 0x19; 58 | break; 59 | case AUDIO_SAMPLE_RATE_32000: 60 | case AUDIO_SAMPLE_RATE_44100: 61 | case AUDIO_SAMPLE_RATE_48000: 62 | i2s_fs_sel = 0x1a; 63 | break; 64 | 65 | default: 66 | log_error("ERROR in hitiny_init_acodec/AUDIO_SAMPLE_RATE: %d (%s)\n", errno, strerror(errno)); 67 | close(fd_acodec); 68 | return -1; 69 | } 70 | 71 | if (ioctl(fd_acodec, ACODEC_SET_I2S1_FS, &i2s_fs_sel)) 72 | { 73 | log_error("ERROR in hitiny_init_acodec/ACODEC_SET_I2S1_FS: %d (%s)\n", errno, strerror(errno)); 74 | ret = -1; 75 | } 76 | 77 | close(fd_acodec); 78 | return ret; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /cfg/sensor_cfg_print.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | void cfg_sensor_pretty_print(const struct SensorConfig* sc) 8 | { 9 | printf("[sensor]\n"); 10 | printf("Sensor_type = %s\n", sc->sensor_type); 11 | printf("DllFile = %s\n", sc->dll_file); 12 | 13 | printf("\n[isp_image]\n"); 14 | printf("Isp_x = %u\n", sc->isp.isp_x); 15 | printf("Isp_y = %u\n", sc->isp.isp_y); 16 | printf("Isp_W = %u\n", sc->isp.isp_w); 17 | printf("Isp_H = %u\n", sc->isp.isp_h); 18 | printf("Isp_FrameRate = %u\n", sc->isp.isp_frame_rate); 19 | 20 | #define COMMENT_VALUES(key, arr, val) { printf(key"%s\n", arr[val]); for (int i = 0; arr[i]; ++i) \ 21 | printf("\t\t\t; %c %s = %d\n", i == val ? '*' : ' ', arr[i], i); } 22 | 23 | COMMENT_VALUES("Isp_bayer = ", cfg_sensor_vals_isp_bayer, sc->isp.isp_bayer); 24 | 25 | printf("\n[vi_dev]\n"); 26 | COMMENT_VALUES("Input_mod = ", cfg_sensor_vals_videv_input_mod, sc->videv.input_mod); 27 | COMMENT_VALUES("Work_mod = ", cfg_sensor_vals_videv_work_mod, sc->videv.work_mod); 28 | COMMENT_VALUES("Combine_mode = ", cfg_sensor_vals_videv_combine_mode, sc->videv.combine_mode); 29 | COMMENT_VALUES("Comp_mode = ", cfg_sensor_vals_videv_comp_mode, sc->videv.comp_mode); 30 | COMMENT_VALUES("Clock_edge = ", cfg_sensor_vals_videv_clock_edge, sc->videv.clock_edge); 31 | 32 | printf("Mask_num = %u\n", sc->videv.mask_num); 33 | printf("Mask_0 = 0x%X\n", sc->videv.mask_0); 34 | printf("Mask_1 = 0x%X\n", sc->videv.mask_1); 35 | 36 | printf("Timingblank_HsyncHfb = %u\t; Horizontal front blanking width\n", sc->videv.timing_blank_hsync_hfb); 37 | printf("Timingblank_HsyncAct = %u\t; Horizontal effetive width\n", sc->videv.timing_blank_hsync_act); 38 | printf("Timingblank_HsyncHbb = %u\t; Horizontal back blanking width\n", sc->videv.timing_blank_hsync_hbb); 39 | printf("Timingblank_VsyncVfb = %u\t; Vertical front blanking height\n", sc->videv.timing_blank_vsync_vfb); 40 | printf("Timingblank_VsyncVact = %u\t; Vertical effetive width\n", sc->videv.timing_blank_vsync_vact); 41 | printf("Timingblank_VsyncVbb = %u\t; Vertical back blanking height\n", sc->videv.timing_blank_vsync_vbb); 42 | printf("Timingblank_VsyncVbfb = %u\t; Even-field vertical front blanking height(interlace, invalid progressive)\n", sc->videv.timing_blank_vsync_vbfb); 43 | printf("Timingblank_VsyncVbact = %u\t; Even-field vertical effetive width(interlace, invalid progressive)\n", sc->videv.timing_blank_vsync_vbact); 44 | printf("Timingblank_VsyncVbbb = %u\t; Even-field vertical back blanking height(interlace, invalid progressive)\n", sc->videv.timing_blank_vsync_vbbb); 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /aux/gmtime.h: -------------------------------------------------------------------------------- 1 | #ifndef __AUX_GMTIME_H__ 2 | #define __AUX_GMTIME_H__ 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | static inline 12 | void aux_gmtime(time_t t, struct tm *tp) 13 | { 14 | int yday; 15 | uintptr_t n, sec, min, hour, mday, mon, year, wday, days, leap; 16 | 17 | /* the calculation is valid for positive time_t only */ 18 | 19 | n = (uintptr_t) t; 20 | days = n / 86400; 21 | 22 | /* Jaunary 1, 1970 was Thursday */ 23 | 24 | wday = (4 + days) % 7; 25 | n %= 86400; 26 | hour = n / 3600; 27 | n %= 3600; 28 | min = n / 60; 29 | sec = n % 60; 30 | 31 | /* 32 | * the algorithm based on Gauss' formula, 33 | * see src/http/ngx_http_parse_time.c 34 | */ 35 | 36 | /* days since March 1, 1 BC */ 37 | days = days - (31 + 28) + 719527; 38 | 39 | /* 40 | * The "days" should be adjusted to 1 only, however, some March 1st's go 41 | * to previous year, so we adjust them to 2. This causes also shift of the 42 | * last Feburary days to next year, but we catch the case when "yday" 43 | * becomes negative. 44 | */ 45 | 46 | year = (days + 2) * 400 / (365 * 400 + 100 - 4 + 1); 47 | yday = days - (365 * year + year / 4 - year / 100 + year / 400); 48 | 49 | if (yday < 0) 50 | { 51 | leap = (year % 4 == 0) && (year % 100 || (year % 400 == 0)); 52 | yday = 365 + leap + yday; 53 | year--; 54 | } 55 | 56 | /* 57 | * The empirical formula that maps "yday" to month. 58 | * There are at least 10 variants, some of them are: 59 | * mon = (yday + 31) * 15 / 459 60 | * mon = (yday + 31) * 17 / 520 61 | * mon = (yday + 31) * 20 / 612 62 | */ 63 | 64 | mon = (yday + 31) * 10 / 306; 65 | 66 | /* the Gauss' formula that evaluates days before the month */ 67 | 68 | mday = yday - (367 * mon / 12 - 30) + 1; 69 | 70 | if (yday >= 306) 71 | { 72 | year++; 73 | mon -= 10; 74 | 75 | /* 76 | * there is no "yday" in Win32 SYSTEMTIME 77 | * 78 | * yday -= 306; 79 | */ 80 | } 81 | else 82 | { 83 | mon += 2; 84 | 85 | /* 86 | * there is no "yday" in Win32 SYSTEMTIME 87 | * 88 | * yday += 31 + 28 + leap; 89 | */ 90 | } 91 | 92 | tp->tm_sec = (int) sec; 93 | tp->tm_min = (int) min; 94 | tp->tm_hour = (int) hour; 95 | tp->tm_mday = (int) mday; 96 | tp->tm_mon = (int) mon; 97 | tp->tm_year = (int) year; 98 | tp->tm_wday = (int) wday; 99 | } 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /* __AUX_GMTIME_H__ */ 106 | -------------------------------------------------------------------------------- /jxh22_i2c/hi_i2c.h: -------------------------------------------------------------------------------- 1 | #ifndef __HI_I2C_H__ 2 | #define __HI_I2C_H__ 3 | 4 | 5 | #ifdef __cplusplus 6 | #if __cplusplus 7 | extern "C" { 8 | #endif 9 | #endif /* __cplusplus */ 10 | 11 | typedef struct I2C_DATA_S 12 | { 13 | unsigned char dev_addr; 14 | unsigned int reg_addr; 15 | unsigned int addr_byte_num; 16 | unsigned int data; 17 | unsigned int data_byte_num; 18 | 19 | }I2C_DATA_S ; 20 | 21 | #define READ_OPERATION (1) 22 | #define WRITE_OPERATION 0xfe 23 | #define CMD_I2C_WRITE 0x01 24 | #define CMD_I2C_READ 0x03 25 | 26 | 27 | /* I2C_CTRL_REG */ 28 | #define I2C_ENABLE (1 << 8) 29 | #define I2C_UNMASK_TOTAL (1 << 7) 30 | #define I2C_UNMASK_START (1 << 6) 31 | #define I2C_UNMASK_END (1 << 5) 32 | #define I2C_UNMASK_SEND (1 << 4) 33 | #define I2C_UNMASK_RECEIVE (1 << 3) 34 | #define I2C_UNMASK_ACK (1 << 2) 35 | #define I2C_UNMASK_ARBITRATE (1<< 1) 36 | #define I2C_UNMASK_OVER (1 << 0) 37 | #define I2C_UNMASK_ALL (I2C_UNMASK_START | I2C_UNMASK_END | \ 38 | I2C_UNMASK_SEND | I2C_UNMASK_RECEIVE | \ 39 | I2C_UNMASK_ACK | I2C_UNMASK_ARBITRATE | \ 40 | I2C_UNMASK_OVER) 41 | 42 | /* I2C_COM_REB */ 43 | #define I2C_SEND_ACK (~(1 << 4)) 44 | #define I2C_START (1 << 3) 45 | #define I2C_READ (1 << 2) 46 | #define I2C_WRITE (1 << 1) 47 | #define I2C_STOP (1 << 0) 48 | 49 | /* I2C_ICR_REG */ 50 | #define I2C_CLEAR_START (1 << 6) 51 | #define I2C_CLEAR_END (1 << 5) 52 | #define I2C_CLEAR_SEND (1 << 4) 53 | #define I2C_CLEAR_RECEIVE (1 << 3) 54 | #define I2C_CLEAR_ACK (1 << 2) 55 | #define I2C_CLEAR_ARBITRATE (1 << 1) 56 | #define I2C_CLEAR_OVER (1 << 0) 57 | #define I2C_CLEAR_ALL (I2C_CLEAR_START | I2C_CLEAR_END | \ 58 | I2C_CLEAR_SEND | I2C_CLEAR_RECEIVE | \ 59 | I2C_CLEAR_ACK | I2C_CLEAR_ARBITRATE | \ 60 | I2C_CLEAR_OVER) 61 | 62 | /* I2C_SR_REG */ 63 | #define I2C_BUSY (1 << 7) 64 | #define I2C_START_INTR (1 << 6) 65 | #define I2C_END_INTR (1 << 5) 66 | #define I2C_SEND_INTR (1 << 4) 67 | #define I2C_RECEIVE_INTR (1 << 3) 68 | #define I2C_ACK_INTR (1 << 2) 69 | #define I2C_ARBITRATE_INTR (1 << 1) 70 | #define I2C_OVER_INTR (1 << 0) 71 | 72 | 73 | int HI_I2C_WriteConfig(unsigned char dev_addr); 74 | int HI_I2C_Write(unsigned char dev_addr, unsigned int reg_addr, unsigned int addr_byte_num, unsigned int data, unsigned int data_byte_num); 75 | int HI_I2C_Read (unsigned char dev_addr, unsigned int reg_addr, unsigned int addr_byte_num, unsigned int data_byte_num); 76 | 77 | 78 | #ifdef __cplusplus 79 | #if __cplusplus 80 | } 81 | #endif 82 | #endif /* __cplusplus */ 83 | 84 | #endif 85 | 86 | 87 | -------------------------------------------------------------------------------- /jxh42_i2c/hi_i2c.h: -------------------------------------------------------------------------------- 1 | #ifndef __HI_I2C_H__ 2 | #define __HI_I2C_H__ 3 | 4 | 5 | #ifdef __cplusplus 6 | #if __cplusplus 7 | extern "C" { 8 | #endif 9 | #endif /* __cplusplus */ 10 | 11 | typedef struct I2C_DATA_S 12 | { 13 | unsigned char dev_addr; 14 | unsigned int reg_addr; 15 | unsigned int addr_byte_num; 16 | unsigned int data; 17 | unsigned int data_byte_num; 18 | 19 | }I2C_DATA_S ; 20 | 21 | #define READ_OPERATION (1) 22 | #define WRITE_OPERATION 0xfe 23 | #define CMD_I2C_WRITE 0x01 24 | #define CMD_I2C_READ 0x03 25 | 26 | 27 | /* I2C_CTRL_REG */ 28 | #define I2C_ENABLE (1 << 8) 29 | #define I2C_UNMASK_TOTAL (1 << 7) 30 | #define I2C_UNMASK_START (1 << 6) 31 | #define I2C_UNMASK_END (1 << 5) 32 | #define I2C_UNMASK_SEND (1 << 4) 33 | #define I2C_UNMASK_RECEIVE (1 << 3) 34 | #define I2C_UNMASK_ACK (1 << 2) 35 | #define I2C_UNMASK_ARBITRATE (1<< 1) 36 | #define I2C_UNMASK_OVER (1 << 0) 37 | #define I2C_UNMASK_ALL (I2C_UNMASK_START | I2C_UNMASK_END | \ 38 | I2C_UNMASK_SEND | I2C_UNMASK_RECEIVE | \ 39 | I2C_UNMASK_ACK | I2C_UNMASK_ARBITRATE | \ 40 | I2C_UNMASK_OVER) 41 | 42 | /* I2C_COM_REB */ 43 | #define I2C_SEND_ACK (~(1 << 4)) 44 | #define I2C_START (1 << 3) 45 | #define I2C_READ (1 << 2) 46 | #define I2C_WRITE (1 << 1) 47 | #define I2C_STOP (1 << 0) 48 | 49 | /* I2C_ICR_REG */ 50 | #define I2C_CLEAR_START (1 << 6) 51 | #define I2C_CLEAR_END (1 << 5) 52 | #define I2C_CLEAR_SEND (1 << 4) 53 | #define I2C_CLEAR_RECEIVE (1 << 3) 54 | #define I2C_CLEAR_ACK (1 << 2) 55 | #define I2C_CLEAR_ARBITRATE (1 << 1) 56 | #define I2C_CLEAR_OVER (1 << 0) 57 | #define I2C_CLEAR_ALL (I2C_CLEAR_START | I2C_CLEAR_END | \ 58 | I2C_CLEAR_SEND | I2C_CLEAR_RECEIVE | \ 59 | I2C_CLEAR_ACK | I2C_CLEAR_ARBITRATE | \ 60 | I2C_CLEAR_OVER) 61 | 62 | /* I2C_SR_REG */ 63 | #define I2C_BUSY (1 << 7) 64 | #define I2C_START_INTR (1 << 6) 65 | #define I2C_END_INTR (1 << 5) 66 | #define I2C_SEND_INTR (1 << 4) 67 | #define I2C_RECEIVE_INTR (1 << 3) 68 | #define I2C_ACK_INTR (1 << 2) 69 | #define I2C_ARBITRATE_INTR (1 << 1) 70 | #define I2C_OVER_INTR (1 << 0) 71 | 72 | 73 | int HI_I2C_WriteConfig(unsigned char dev_addr); 74 | int HI_I2C_Write(unsigned char dev_addr, unsigned int reg_addr, unsigned int addr_byte_num, unsigned int data, unsigned int data_byte_num); 75 | int HI_I2C_Read (unsigned char dev_addr, unsigned int reg_addr, unsigned int addr_byte_num, unsigned int data_byte_num); 76 | 77 | 78 | #ifdef __cplusplus 79 | #if __cplusplus 80 | } 81 | #endif 82 | #endif /* __cplusplus */ 83 | 84 | #endif 85 | 86 | 87 | -------------------------------------------------------------------------------- /imx225_i2c/hi_i2c.h: -------------------------------------------------------------------------------- 1 | #ifndef __HI_I2C_H__ 2 | #define __HI_I2C_H__ 3 | 4 | 5 | #ifdef __cplusplus 6 | #if __cplusplus 7 | extern "C" { 8 | #endif 9 | #endif /* __cplusplus */ 10 | 11 | typedef struct I2C_DATA_S 12 | { 13 | unsigned char dev_addr; 14 | unsigned int reg_addr; 15 | unsigned int addr_byte_num; 16 | unsigned int data; 17 | unsigned int data_byte_num; 18 | 19 | }I2C_DATA_S ; 20 | 21 | #define READ_OPERATION (1) 22 | #define WRITE_OPERATION 0xfe 23 | #define CMD_I2C_WRITE 0x01 24 | #define CMD_I2C_READ 0x03 25 | 26 | 27 | /* I2C_CTRL_REG */ 28 | #define I2C_ENABLE (1 << 8) 29 | #define I2C_UNMASK_TOTAL (1 << 7) 30 | #define I2C_UNMASK_START (1 << 6) 31 | #define I2C_UNMASK_END (1 << 5) 32 | #define I2C_UNMASK_SEND (1 << 4) 33 | #define I2C_UNMASK_RECEIVE (1 << 3) 34 | #define I2C_UNMASK_ACK (1 << 2) 35 | #define I2C_UNMASK_ARBITRATE (1<< 1) 36 | #define I2C_UNMASK_OVER (1 << 0) 37 | #define I2C_UNMASK_ALL (I2C_UNMASK_START | I2C_UNMASK_END | \ 38 | I2C_UNMASK_SEND | I2C_UNMASK_RECEIVE | \ 39 | I2C_UNMASK_ACK | I2C_UNMASK_ARBITRATE | \ 40 | I2C_UNMASK_OVER) 41 | 42 | /* I2C_COM_REB */ 43 | #define I2C_SEND_ACK (~(1 << 4)) 44 | #define I2C_START (1 << 3) 45 | #define I2C_READ (1 << 2) 46 | #define I2C_WRITE (1 << 1) 47 | #define I2C_STOP (1 << 0) 48 | 49 | /* I2C_ICR_REG */ 50 | #define I2C_CLEAR_START (1 << 6) 51 | #define I2C_CLEAR_END (1 << 5) 52 | #define I2C_CLEAR_SEND (1 << 4) 53 | #define I2C_CLEAR_RECEIVE (1 << 3) 54 | #define I2C_CLEAR_ACK (1 << 2) 55 | #define I2C_CLEAR_ARBITRATE (1 << 1) 56 | #define I2C_CLEAR_OVER (1 << 0) 57 | #define I2C_CLEAR_ALL (I2C_CLEAR_START | I2C_CLEAR_END | \ 58 | I2C_CLEAR_SEND | I2C_CLEAR_RECEIVE | \ 59 | I2C_CLEAR_ACK | I2C_CLEAR_ARBITRATE | \ 60 | I2C_CLEAR_OVER) 61 | 62 | /* I2C_SR_REG */ 63 | #define I2C_BUSY (1 << 7) 64 | #define I2C_START_INTR (1 << 6) 65 | #define I2C_END_INTR (1 << 5) 66 | #define I2C_SEND_INTR (1 << 4) 67 | #define I2C_RECEIVE_INTR (1 << 3) 68 | #define I2C_ACK_INTR (1 << 2) 69 | #define I2C_ARBITRATE_INTR (1 << 1) 70 | #define I2C_OVER_INTR (1 << 0) 71 | 72 | 73 | int HI_I2C_WriteConfig(unsigned char dev_addr); 74 | int HI_I2C_Write(unsigned char dev_addr, unsigned int reg_addr, unsigned int addr_byte_num, unsigned int data, unsigned int data_byte_num); 75 | int HI_I2C_Read (unsigned char dev_addr, unsigned int reg_addr, unsigned int addr_byte_num, unsigned int data_byte_num); 76 | 77 | 78 | #ifdef __cplusplus 79 | #if __cplusplus 80 | } 81 | #endif 82 | #endif /* __cplusplus */ 83 | 84 | #endif 85 | 86 | 87 | -------------------------------------------------------------------------------- /imx225_i2c_960h/hi_i2c.h: -------------------------------------------------------------------------------- 1 | #ifndef __HI_I2C_H__ 2 | #define __HI_I2C_H__ 3 | 4 | 5 | #ifdef __cplusplus 6 | #if __cplusplus 7 | extern "C" { 8 | #endif 9 | #endif /* __cplusplus */ 10 | 11 | typedef struct I2C_DATA_S 12 | { 13 | unsigned char dev_addr; 14 | unsigned int reg_addr; 15 | unsigned int addr_byte_num; 16 | unsigned int data; 17 | unsigned int data_byte_num; 18 | 19 | }I2C_DATA_S ; 20 | 21 | #define READ_OPERATION (1) 22 | #define WRITE_OPERATION 0xfe 23 | #define CMD_I2C_WRITE 0x01 24 | #define CMD_I2C_READ 0x03 25 | 26 | 27 | /* I2C_CTRL_REG */ 28 | #define I2C_ENABLE (1 << 8) 29 | #define I2C_UNMASK_TOTAL (1 << 7) 30 | #define I2C_UNMASK_START (1 << 6) 31 | #define I2C_UNMASK_END (1 << 5) 32 | #define I2C_UNMASK_SEND (1 << 4) 33 | #define I2C_UNMASK_RECEIVE (1 << 3) 34 | #define I2C_UNMASK_ACK (1 << 2) 35 | #define I2C_UNMASK_ARBITRATE (1<< 1) 36 | #define I2C_UNMASK_OVER (1 << 0) 37 | #define I2C_UNMASK_ALL (I2C_UNMASK_START | I2C_UNMASK_END | \ 38 | I2C_UNMASK_SEND | I2C_UNMASK_RECEIVE | \ 39 | I2C_UNMASK_ACK | I2C_UNMASK_ARBITRATE | \ 40 | I2C_UNMASK_OVER) 41 | 42 | /* I2C_COM_REB */ 43 | #define I2C_SEND_ACK (~(1 << 4)) 44 | #define I2C_START (1 << 3) 45 | #define I2C_READ (1 << 2) 46 | #define I2C_WRITE (1 << 1) 47 | #define I2C_STOP (1 << 0) 48 | 49 | /* I2C_ICR_REG */ 50 | #define I2C_CLEAR_START (1 << 6) 51 | #define I2C_CLEAR_END (1 << 5) 52 | #define I2C_CLEAR_SEND (1 << 4) 53 | #define I2C_CLEAR_RECEIVE (1 << 3) 54 | #define I2C_CLEAR_ACK (1 << 2) 55 | #define I2C_CLEAR_ARBITRATE (1 << 1) 56 | #define I2C_CLEAR_OVER (1 << 0) 57 | #define I2C_CLEAR_ALL (I2C_CLEAR_START | I2C_CLEAR_END | \ 58 | I2C_CLEAR_SEND | I2C_CLEAR_RECEIVE | \ 59 | I2C_CLEAR_ACK | I2C_CLEAR_ARBITRATE | \ 60 | I2C_CLEAR_OVER) 61 | 62 | /* I2C_SR_REG */ 63 | #define I2C_BUSY (1 << 7) 64 | #define I2C_START_INTR (1 << 6) 65 | #define I2C_END_INTR (1 << 5) 66 | #define I2C_SEND_INTR (1 << 4) 67 | #define I2C_RECEIVE_INTR (1 << 3) 68 | #define I2C_ACK_INTR (1 << 2) 69 | #define I2C_ARBITRATE_INTR (1 << 1) 70 | #define I2C_OVER_INTR (1 << 0) 71 | 72 | 73 | int HI_I2C_WriteConfig(unsigned char dev_addr); 74 | int HI_I2C_Write(unsigned char dev_addr, unsigned int reg_addr, unsigned int addr_byte_num, unsigned int data, unsigned int data_byte_num); 75 | int HI_I2C_Read (unsigned char dev_addr, unsigned int reg_addr, unsigned int addr_byte_num, unsigned int data_byte_num); 76 | 77 | 78 | #ifdef __cplusplus 79 | #if __cplusplus 80 | } 81 | #endif 82 | #endif /* __cplusplus */ 83 | 84 | #endif 85 | 86 | 87 | -------------------------------------------------------------------------------- /tinydraw/font.c: -------------------------------------------------------------------------------- 1 | #include "font.h" 2 | #include 3 | 4 | void tinydraw_renderer_draw_char(tinydraw_renderer_ctx_t *ctx, uint16_t x, uint16_t y, const tinydraw_font_t *fnt, utf8_char_t c) 5 | { 6 | tinydraw_font_symbol_t sym; 7 | 8 | if (!fnt->lookup(c, &sym)) 9 | { 10 | if (c > ' ') 11 | { 12 | if (!fnt->lookup('?', &sym)) return; 13 | } 14 | else 15 | { 16 | sym.margin_top = fnt->height + 1; 17 | } 18 | } 19 | 20 | uint8_t font_width = fnt->width; 21 | uint8_t font_height = fnt->height; 22 | 23 | uint8_t top = sym.margin_top; 24 | uint8_t bottom = font_height - sym.margin_bottom - 1; 25 | uint8_t left = sym.margin_left; 26 | uint8_t right = font_width - sym.margin_right-1; 27 | 28 | uint16_t bi = sym.bmp_index; 29 | 30 | uint8_t i = 0; 31 | for (unsigned h = 0; (h < font_height) && (ctx->height > y + h); h++) 32 | { 33 | //unsigned pos_start = 2 * ctx->width * (y + h); 34 | uint16_t *pos_start = (uint16_t*)ctx->buffer + ctx->width * (y + h) + x; 35 | 36 | for (unsigned w = 0; w < font_width; w++) 37 | { 38 | uint8_t color_pixel = 0; 39 | //if (w < left || w > right || h < top || h > bottom) 40 | if (w >= left && w <= right && h >= top && h <= bottom) 41 | { 42 | color_pixel = (fnt->bmp_base[bi] >> i) & 0x03; 43 | 44 | if (i >= 6) { i = 0; ++bi; } else { i += 2; } 45 | } 46 | 47 | if (ctx->width > x + w) pos_start[w] = ctx->font_draw_colors[color_pixel]; 48 | } 49 | } 50 | } 51 | 52 | static utf8_char_t utf8_getchar(const char **const ss) 53 | { 54 | const uint8_t* const s = (const uint8_t*)*ss; 55 | (*ss)++; 56 | if (s[0] < 0x80) return s[0]; 57 | 58 | (*ss)++; 59 | if (s[0] < 0xC0) return -1; 60 | 61 | (*ss)++; 62 | if (s[0] < 0xE0) return (s[0] & 0x1F) << 6 | s[1] & 0x3F; 63 | 64 | (*ss)++; 65 | if (s[0] < 0xF0) return (s[0] & 0xF) << 12 | (s[1] & 0x3F) << 6 | (s[2] & 0x3F); 66 | 67 | (*ss)++; 68 | if (s[0] < 0xF8) return (s[0] & 0x7) << 18 | (s[1] & 0x3F) << 12 | (s[2] & 0x3F) << 6 | (s[3] & 0x3F); 69 | 70 | (*ss)++; 71 | if (s[0] < 0xFC) return (s[0] & 0x3) << 24 | (s[1] & 0x3F) << 18 | (s[2] & 0x3F) << 12 | (s[3] & 0x3F) << 6 | (s[4] & 0x3F); 72 | 73 | (*ss)++; 74 | return (s[0] & 0x1) << 30 | (s[1] & 0x3F) << 24 | (s[2] & 0x3F) << 18 | (s[3] & 0x3F) << 12 | (s[4] & 0x3F) << 6 | (s[5] & 0x3F); 75 | } 76 | 77 | void tinydraw_renderer_draw_string(tinydraw_renderer_ctx_t *ctx, uint16_t x, uint16_t y, const tinydraw_font_t *fnt, const char* s) 78 | { 79 | const char* it = s; 80 | uint16_t plus_x = 0; 81 | 82 | while (*it) 83 | { 84 | utf8_char_t c = utf8_getchar(&it); 85 | 86 | tinydraw_renderer_draw_char(ctx, x + plus_x, y, fnt, c); 87 | 88 | plus_x += fnt->width; 89 | } 90 | } 91 | 92 | -------------------------------------------------------------------------------- /hitiny/hitiny_region.c: -------------------------------------------------------------------------------- 1 | #include "hitiny_region.h" 2 | #include 3 | #include 4 | #include 5 | 6 | int g_rgn_fd = -1; 7 | 8 | int hitiny_region_init() 9 | { 10 | if (g_rgn_fd >= 0) return 0; 11 | 12 | int fd = hitiny_open_dev("/dev/rgn"); 13 | if (fd < 0) return fd; 14 | 15 | g_rgn_fd = fd; 16 | 17 | return 0; 18 | } 19 | 20 | struct mpi_rgn_create_param_s 21 | { 22 | RGN_HANDLE Handle; 23 | RGN_ATTR_S stRegion; 24 | }; 25 | 26 | int hitiny_MPI_RGN_Create(RGN_HANDLE Handle, const RGN_ATTR_S *pstRegion) 27 | { 28 | hitiny_region_init(); 29 | 30 | if (g_rgn_fd < 0) return 0xA0128010; 31 | if (!pstRegion) return 0xA0128006; 32 | 33 | struct mpi_rgn_create_param_s param; 34 | param.Handle = Handle; 35 | param.stRegion = *pstRegion; 36 | 37 | return ioctl(g_rgn_fd, 0xC0185200, ¶m); 38 | } 39 | 40 | struct mpi_rgn_attach_param_s 41 | { 42 | RGN_HANDLE Handle; 43 | MPP_CHN_S stChn; 44 | RGN_CHN_ATTR_S stChnAttr; 45 | }; 46 | 47 | int hitiny_MPI_RGN_AttachToChn(RGN_HANDLE Handle,const MPP_CHN_S *pstChn, const RGN_CHN_ATTR_S *pstChnAttr) 48 | { 49 | hitiny_region_init(); 50 | 51 | if (g_rgn_fd < 0) return 0xA0128010; 52 | if (!pstChn || !pstChnAttr) return 0xA0128006; 53 | 54 | struct mpi_rgn_attach_param_s param; 55 | param.stChn = *pstChn; 56 | param.Handle = Handle; 57 | param.stChnAttr = *pstChnAttr; 58 | 59 | return ioctl(g_rgn_fd, 0x40485208, ¶m); 60 | }; 61 | 62 | struct mpi_rgn_detach_param_s 63 | { 64 | RGN_HANDLE Handle; 65 | MPP_CHN_S stChn; 66 | }; 67 | 68 | int hitiny_MPI_RGN_DetachFrmChn(RGN_HANDLE Handle, const MPP_CHN_S *pstChn) 69 | { 70 | hitiny_region_init(); 71 | 72 | if (g_rgn_fd < 0) return 0xA0128010; 73 | if (!pstChn) return 0xA0128006; 74 | 75 | struct mpi_rgn_detach_param_s param; 76 | param.Handle = Handle; 77 | param.stChn = *pstChn; 78 | 79 | return ioctl(g_rgn_fd, 0xC0105209, ¶m); 80 | } 81 | 82 | struct mpi_rgn_set_bitmap_s 83 | { 84 | RGN_HANDLE Handle; 85 | BITMAP_S bmp; 86 | }; 87 | 88 | int hitiny_MPI_RGN_SetBitMap(RGN_HANDLE Handle, const BITMAP_S *pstBitmap) 89 | { 90 | hitiny_region_init(); 91 | 92 | if (g_rgn_fd < 0) return 0xA0128010; 93 | if (!pstBitmap) return 0xA0128006; 94 | 95 | struct mpi_rgn_set_bitmap_s param; 96 | param.Handle = Handle; 97 | param.bmp = *pstBitmap; 98 | 99 | return ioctl(g_rgn_fd, 0x40145204, ¶m); 100 | } 101 | 102 | int hitiny_MPI_RGN_Destroy(RGN_HANDLE Handle) 103 | { 104 | hitiny_region_init(); 105 | 106 | if (g_rgn_fd < 0) return 0xA0128010; 107 | 108 | RGN_HANDLE param = Handle; 109 | return ioctl(g_rgn_fd, 0x40045201, ¶m); 110 | } 111 | 112 | void hitiny_region_done() 113 | { 114 | if (g_rgn_fd >= 0) 115 | { 116 | close(g_rgn_fd); 117 | g_rgn_fd = -1; 118 | } 119 | } 120 | 121 | -------------------------------------------------------------------------------- /test/data/test_pumap_vi/vi_gad_ex2: -------------------------------------------------------------------------------- 1 | 2 | [VIU] Version: [Hi3518_MPP_V1.0.B.0 ], Build Time: [Nov 19 2015, 16:37:05] 3 | 4 | -----MODULE PARAM-------------------------------------------------------------- 5 | detect_err_frame drop_err_frame stop_int_level max_cas_gap 6 | 0 0 0 28000 7 | 8 | -----VI DEV ATTR--------------------------------------------------------------- 9 | Dev IntfM WkM ComMsk0 ComMsk1 ScanM AD0 AD1 AD2 AD3 Seq DPath DType DRev 10 | 0 DC 1Mux fff00000 0 P -1 -1 -1 -1 YUYV ISP RGB N 11 | 12 | -----VI HIGH DEV ATTR--------------------------------------------------------------- 13 | Dev InputM WkM ComMsk0 ComMsk1 ScanM AD0 AD1 AD2 AD3 Seq CombM CompM ClkM Fix FldP DPath DType DRev 14 | 15 | -----VI PHYCHN ATTR------------------------------------------------------------ 16 | PhyChn CapX CapY CapW CapH DstW DstH CapSel Mirror Flip IntEn PixFom SrcRat DstRat 17 | 0 0 0 1280 720 1280 720 both N N Y sp420 -1 -1 18 | 19 | -----VI PHYCHN STATUS 1---------------------------------------------------------- 20 | PhyChn Dev IntCnt VbFail LosInt TopLos BotLos BufCnt IntT SendT Field Stride 21 | 0 0 0 0 0 0 0 0 0 0 (null) 0 22 | 23 | -----VI PHYCHN STATUS 2--------------------------------------------------------- 24 | PhyChn MaxIntT IntGapT MaxGapT OverCnt LIntCnt ThrCnt AutoDis CasAutD TmgErr ccErrN IntRat 25 | 0 0 0 0 0 0 0 0 0 0 0 0 26 | 27 | -----VI OTHER ATTR------------------------------------------------------------ 28 | LDC Mode Ratio COffX COffY Enable 29 | -- All 0 0 0 0 30 | 31 | Flash Mode StartTime DuraTime InterVal CapIdx Enable FlashedNum 32 | -- Once 0 0 0 0 0 0 33 | 34 | CSC Type HueVal ContrVal LumaVal StatuVal 35 | -- 709 50 50 50 50 36 | 37 | -----VI EXTCHN ATTR------------------------------------------------------------ 38 | ExtChn BindChn DstW DstH PixFom SrcRat DstRat 39 | 40 | -----VI CHN STATUS------------------------------------------------------------- 41 | ViChn bEnUsrP FrmTime FrmRate SendCnt SwLost Rotate 422to420 42 | 0 N 0 0 0 0 NONE N 43 | 44 | -----VI CHN CALL DSU STATUS 1------------------------------------------------- 45 | ViChn UsrBgnNOk UsrCancel UsrEndOk UsrCbOk CvrBgnNOk CvrCancel CvrEndOk CvrCbOk 46 | 47 | -----VI CHN CALL DSU STATUS 2------------------------------------------------- 48 | ViChn OsdBgnNOk OsdCancel OsdEndOk OsdCbOk ScaleNOk SclCancel SclEndOk SclCbOk 49 | 50 | -----VI CHN CALL DSU STATUS 3------------------------------------------------- 51 | ViChn RotateNOk RotCancel RotEndOk RotCbOk LDCNOk LDCCancel LDCEndOk LDCCbOk 52 | -------------------------------------------------------------------------------- /test/data/test_pumap_vi/vi_ds06_majestic: -------------------------------------------------------------------------------- 1 | 2 | [VIU] Version: [Hi3518_MPP_V1.0.B.0 ], Build Time: [Nov 19 2015, 16:37:05] 3 | 4 | -----MODULE PARAM-------------------------------------------------------------- 5 | detect_err_frame drop_err_frame stop_int_level max_cas_gap 6 | 0 0 0 28000 7 | 8 | -----VI DEV ATTR--------------------------------------------------------------- 9 | Dev IntfM WkM ComMsk0 ComMsk1 ScanM AD0 AD1 AD2 AD3 Seq DPath DType DRev 10 | 0 DC 1Mux fff00000 0 P -1 -1 -1 -1 YUYV ISP RGB N 11 | 12 | -----VI HIGH DEV ATTR--------------------------------------------------------------- 13 | Dev InputM WkM ComMsk0 ComMsk1 ScanM AD0 AD1 AD2 AD3 Seq CombM CompM ClkM Fix FldP DPath DType DRev 14 | 15 | -----VI PHYCHN ATTR------------------------------------------------------------ 16 | PhyChn CapX CapY CapW CapH DstW DstH CapSel Mirror Flip IntEn PixFom SrcRat DstRat 17 | 0 0 0 1280 720 1280 720 both N N Y sp420 -1 -1 18 | 19 | -----VI PHYCHN STATUS 1---------------------------------------------------------- 20 | PhyChn Dev IntCnt VbFail LosInt TopLos BotLos BufCnt IntT SendT Field Stride 21 | 0 0 2716 0 2 0 2 2 137 53 frm 1280 22 | 23 | -----VI PHYCHN STATUS 2--------------------------------------------------------- 24 | PhyChn MaxIntT IntGapT MaxGapT OverCnt LIntCnt ThrCnt AutoDis CasAutD TmgErr ccErrN IntRat 25 | 0 173 33330 33385 0 0 1 0 0 0 2 30 26 | 27 | -----VI OTHER ATTR------------------------------------------------------------ 28 | LDC Mode Ratio COffX COffY Enable 29 | -- All 0 0 0 0 30 | 31 | Flash Mode StartTime DuraTime InterVal CapIdx Enable FlashedNum 32 | -- Once 0 0 0 0 0 0 33 | 34 | CSC Type HueVal ContrVal LumaVal StatuVal 35 | -- 709 64 80 81 85 36 | 37 | -----VI EXTCHN ATTR------------------------------------------------------------ 38 | ExtChn BindChn DstW DstH PixFom SrcRat DstRat 39 | 40 | -----VI CHN STATUS------------------------------------------------------------- 41 | ViChn bEnUsrP FrmTime FrmRate SendCnt SwLost Rotate 422to420 42 | 0 N 33329 30 2714 0 NONE N 43 | 44 | -----VI CHN CALL DSU STATUS 1------------------------------------------------- 45 | ViChn UsrBgnNOk UsrCancel UsrEndOk UsrCbOk CvrBgnNOk CvrCancel CvrEndOk CvrCbOk 46 | 47 | -----VI CHN CALL DSU STATUS 2------------------------------------------------- 48 | ViChn OsdBgnNOk OsdCancel OsdEndOk OsdCbOk ScaleNOk SclCancel SclEndOk SclCbOk 49 | 50 | -----VI CHN CALL DSU STATUS 3------------------------------------------------- 51 | ViChn RotateNOk RotCancel RotEndOk RotCbOk LDCNOk LDCCancel LDCEndOk LDCCbOk 52 | -------------------------------------------------------------------------------- /test/data/test_pumap_vi/vi_gad_ex1: -------------------------------------------------------------------------------- 1 | 2 | [VIU] Version: [Hi3518_MPP_V1.0.B.0 ], Build Time: [Nov 19 2015, 16:37:05] 3 | 4 | -----MODULE PARAM-------------------------------------------------------------- 5 | detect_err_frame drop_err_frame stop_int_level max_cas_gap 6 | 0 0 0 28000 7 | 8 | -----VI DEV ATTR--------------------------------------------------------------- 9 | Dev IntfM WkM ComMsk0 ComMsk1 ScanM AD0 AD1 AD2 AD3 Seq DPath DType DRev 10 | 11 | -----VI HIGH DEV ATTR--------------------------------------------------------------- 12 | Dev InputM WkM ComMsk0 ComMsk1 ScanM AD0 AD1 AD2 AD3 Seq CombM CompM ClkM Fix FldP DPath DType DRev 13 | 0 BT656 1Mux fff00000 0 P -1 -1 -1 -1 YUYV COMP SING UP 1 STD ISP RGB N 14 | 15 | -----VI PHYCHN ATTR------------------------------------------------------------ 16 | PhyChn CapX CapY CapW CapH DstW DstH CapSel Mirror Flip IntEn PixFom SrcRat DstRat 17 | 0 0 0 1280 720 1280 720 both N N Y sp420 30 30 18 | 19 | -----VI PHYCHN STATUS 1---------------------------------------------------------- 20 | PhyChn Dev IntCnt VbFail LosInt TopLos BotLos BufCnt IntT SendT Field Stride 21 | 0 0 243 0 2 0 2 2 513 322 frm 1280 22 | 23 | -----VI PHYCHN STATUS 2--------------------------------------------------------- 24 | PhyChn MaxIntT IntGapT MaxGapT OverCnt LIntCnt ThrCnt AutoDis CasAutD TmgErr ccErrN IntRat 25 | 0 517 33339 33610 0 0 1 0 0 0 2 29 26 | 27 | -----VI OTHER ATTR------------------------------------------------------------ 28 | LDC Mode Ratio COffX COffY Enable 29 | -- All 0 0 0 0 30 | 31 | Flash Mode StartTime DuraTime InterVal CapIdx Enable FlashedNum 32 | -- Once 0 0 0 0 0 0 33 | 34 | CSC Type HueVal ContrVal LumaVal StatuVal 35 | -- 709 50 50 50 50 36 | 37 | -----VI EXTCHN ATTR------------------------------------------------------------ 38 | ExtChn BindChn DstW DstH PixFom SrcRat DstRat 39 | 40 | -----VI CHN STATUS------------------------------------------------------------- 41 | ViChn bEnUsrP FrmTime FrmRate SendCnt SwLost Rotate 422to420 42 | 0 N 33340 0 241 0 NONE N 43 | 44 | -----VI CHN CALL DSU STATUS 1------------------------------------------------- 45 | ViChn UsrBgnNOk UsrCancel UsrEndOk UsrCbOk CvrBgnNOk CvrCancel CvrEndOk CvrCbOk 46 | 47 | -----VI CHN CALL DSU STATUS 2------------------------------------------------- 48 | ViChn OsdBgnNOk OsdCancel OsdEndOk OsdCbOk ScaleNOk SclCancel SclEndOk SclCbOk 49 | 50 | -----VI CHN CALL DSU STATUS 3------------------------------------------------- 51 | ViChn RotateNOk RotCancel RotEndOk RotCbOk LDCNOk LDCCancel LDCEndOk LDCCbOk 52 | -------------------------------------------------------------------------------- /devices/BLK18E_0042/reverse/proc-umap-vi.txt: -------------------------------------------------------------------------------- 1 | # cat /proc/umap/vi 2 | 3 | [VIU] Version: [Hi3518_MPP_V1.0.A.0 ], Build Time: [Apr 1 2015, 19:36:33] 4 | 5 | -----MODULE PARAM-------------------------------------------------------------- 6 | detect_err_frame drop_err_frame stop_int_level max_cas_gap 7 | 0 0 0 28000 8 | 9 | -----VI DEV ATTR--------------------------------------------------------------- 10 | Dev IntfM WkM ComMsk0 ComMsk1 ScanM AD0 AD1 AD2 AD3 Seq DPath DType DRev 11 | 0 DC 1Mux 3ff00000 0 P -1 -1 -1 -1 YUYV ISP RGB N 12 | 13 | -----VI HIGH DEV ATTR--------------------------------------------------------------- 14 | Dev InputM WkM ComMsk0 ComMsk1 ScanM AD0 AD1 AD2 AD3 Seq CombM CompM ClkM Fix FldP DPath DType DRev 15 | 16 | -----VI PHYCHN ATTR------------------------------------------------------------ 17 | PhyChn CapX CapY CapW CapH DstW DstH CapSel Mirror Flip IntEn PixFom SrcRat DstRat 18 | 0 0 0 1280 720 1280 720 both N N Y sp420 25 25 19 | 20 | -----VI PHYCHN STATUS 1---------------------------------------------------------- 21 | PhyChn Dev IntCnt VbFail LosInt TopLos BotLos BufCnt IntT SendT Field Stride 22 | 0 0 7086 0 3 0 2 2 507 355 frm 1280 23 | 24 | -----VI PHYCHN STATUS 2--------------------------------------------------------- 25 | PhyChn MaxIntT IntGapT MaxGapT OverCnt LIntCnt ThrCnt AutoDis CasAutD TmgErr ccErrN IntRat 26 | 0 649 80069 80265 6996 0 1 0 0 0 3 12 27 | 28 | -----VI OTHER ATTR------------------------------------------------------------ 29 | LDC Mode Ratio COffX COffY Enable 30 | -- All 0 0 0 0 31 | 32 | Flash Mode StartTime DuraTime InterVal CapIdx Enable FlashedNum 33 | -- Once 0 0 0 0 0 0 34 | 35 | CSC Type HueVal ContrVal LumaVal StatuVal 36 | -- 709 50 50 50 50 37 | 38 | -----VI EXTCHN ATTR------------------------------------------------------------ 39 | ExtChn BindChn DstW DstH PixFom SrcRat DstRat 40 | 41 | -----VI CHN STATUS------------------------------------------------------------- 42 | ViChn bEnUsrP FrmTime FrmRate SendCnt SwLost Rotate 422to420 43 | 0 N 80070 12 7083 0 NONE N 44 | 45 | -----VI CHN CALL DSU STATUS 1------------------------------------------------- 46 | ViChn UsrBgnNOk UsrCancel UsrEndOk UsrCbOk CvrBgnNOk CvrCancel CvrEndOk CvrCbOk 47 | 48 | -----VI CHN CALL DSU STATUS 2------------------------------------------------- 49 | ViChn OsdBgnNOk OsdCancel OsdEndOk OsdCbOk ScaleNOk SclCancel SclEndOk SclCbOk 50 | 51 | -----VI CHN CALL DSU STATUS 3------------------------------------------------- 52 | ViChn RotateNOk RotCancel RotEndOk RotCbOk LDCNOk LDCCancel LDCEndOk LDCCbOk 53 | 54 | -------------------------------------------------------------------------------- /hisinad/daemon.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "mpi_venc.h" 13 | #include "mpi_sys.h" 14 | 15 | int stop_flag = 0; 16 | 17 | void action_on_signal(int signum) 18 | { 19 | log_info("STOP"); 20 | stop_flag = 1; 21 | } 22 | 23 | void print_error(int ret) 24 | { 25 | if (-1 == ret) 26 | { 27 | log_error("I/O error, %d: %s", errno, strerror(errno)); 28 | } 29 | else 30 | { 31 | log_error("Error %s(%d) at line %u, pos %u", cfg_proc_err_msg(ret), ret, cfg_proc_err_line_num(), cfg_proc_err_line_pos()); 32 | if (ret == CFG_PROC_WRONG_SECTION) 33 | { 34 | log_error("Wrong section name [%s]", cfg_sensor_read_error_value()); 35 | } 36 | else if (ret == CFG_PROC_KEY_BAD) 37 | { 38 | log_error("Wrong key \"%s\"", cfg_sensor_read_error_key()); 39 | } 40 | else if (ret == CFG_PROC_VALUE_BAD) 41 | { 42 | log_error("Wrong value \"%s\" for %s", cfg_sensor_read_error_value(), cfg_sensor_read_error_key()); 43 | } 44 | } 45 | } 46 | 47 | void usage_exit() 48 | { 49 | log_error("./test_ao [--no-daemon] sensor_config.ini"); 50 | exit(-1); 51 | } 52 | 53 | int main(int argc, char** argv) 54 | { 55 | if (argc < 2) usage_exit(); 56 | 57 | int deamon_mode = strcmp(argv[1], "--no-daemon"); 58 | if (argc == 2 && !deamon_mode) usage_exit(); 59 | 60 | signal(SIGINT, action_on_signal); 61 | signal(SIGTERM, action_on_signal); 62 | 63 | struct SensorConfig sc; 64 | memset(&sc, 0, sizeof(struct SensorConfig)); 65 | 66 | int ret = cfg_sensor_read(argv[argc - 1], &sc); 67 | 68 | if (ret < 0) 69 | { 70 | print_error(ret); 71 | return ret; 72 | } 73 | 74 | if (sc.vb_cnt < 4) 75 | { 76 | log_warn("WARNING! vb_cnt is not set or less than 4, setting it to default 5 buffers..."); 77 | sc.vb_cnt = 5; 78 | } 79 | 80 | if (deamon_mode) 81 | { 82 | log_info("Daemonize and log to /tmp/hisinad.log"); 83 | char buf[128]; 84 | snprintf(buf, 128, "/tmp/hisinad.log"); 85 | log_create(buf, LOG_info); 86 | 87 | if (fork()) exit(0); 88 | } 89 | 90 | ret = sdk_init(&sc); 91 | if (ret < 0) 92 | { 93 | log_error("sdk_init() failed at %s: 0x%X", __sdk_last_call, ret); 94 | return -1; 95 | } 96 | 97 | ret = sdk_sensor_init(&sc); 98 | if (ret < 0) 99 | { 100 | log_error("sdk_sensor_init() failed: %d", ret); 101 | sdk_done(); 102 | return ret; 103 | } 104 | 105 | ret = sdk_isp_init(&sc); 106 | if (ret < 0) 107 | { 108 | log_error("sdk_isp_init() failed: %d", ret); 109 | sdk_sensor_done(); 110 | sdk_done(); 111 | return ret; 112 | } 113 | 114 | ret = sdk_vi_init(&sc); 115 | 116 | if (!ret) 117 | { 118 | sdk_vpss_init(&sc); 119 | 120 | log_info("daemon ready, running...\n"); 121 | while (!stop_flag) 122 | { 123 | sleep(1); 124 | } 125 | } 126 | 127 | log_info("closing isp..."); 128 | sdk_isp_done(); 129 | log_info("done"); 130 | sdk_sensor_done(); 131 | sdk_done(); 132 | log_info("daemon exit"); 133 | 134 | return 0; 135 | } 136 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /aux/fonts/render.h: -------------------------------------------------------------------------------- 1 | #ifndef _RENDER_H_ 2 | #define _RENDER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "font.h" 14 | #include "hi_comm_video.h" 15 | 16 | //========================================================================= 17 | 18 | #define BLACK_COLOR 0x0000 19 | #define WHITE_COLOR 0xFFFF 20 | #define RED_COLOR 0xF800 21 | #define GREEN_COLOR 0x07E0 22 | #define BLUE_COLOR 0x001F 23 | #define CYAN_COLOR 0x07FF 24 | #define YELLOW_COLOR 0xFFE0 25 | #define PURPLE_COLOR 0xF81F 26 | #define LIGHT_GREY_COLOR 0xAD55 27 | #define DARK_GREY_COLOR 0x52AA 28 | 29 | #define DEFALT_BG_COLOR BLACK_COLOR 30 | #define DEFALT_BRUSH_COLOR WHITE_COLOR 31 | 32 | #define RGB565_TO_R8(color) (((color) & 0xF800) >> 8) 33 | #define RGB565_TO_G8(color) (((color) & 0x07E0) >> 3) 34 | #define RGB565_TO_B8(color) (((color) & 0x001F) << 3) 35 | 36 | #define RGB888_TO_RGB565(r,g,b) (((((color_t)r) & 0b11111000) << 8) | ((((color_t)g) & 0b11111100) << 3) | (((color_t)b) >> 3)) 37 | 38 | //========================================================================= 39 | 40 | #ifndef MIN 41 | #define MIN(a,b)(ab?a:b) 46 | #endif 47 | 48 | //========================================================================= 49 | 50 | typedef uint16_t color_t; 51 | 52 | typedef struct { 53 | uint32_t x; 54 | uint32_t y; 55 | } point_t; 56 | 57 | typedef struct { 58 | uint32_t x0; 59 | uint32_t y0; 60 | uint32_t x1; 61 | uint32_t y1; 62 | } rect_t; 63 | 64 | #pragma pack(push,1) 65 | typedef struct{ 66 | uint8_t signature[2]; 67 | uint32_t filesize; 68 | uint32_t reserved; 69 | uint32_t fileoffset_to_pixelarray; 70 | } fileheader; 71 | typedef struct{ 72 | uint32_t dibheadersize; 73 | uint32_t width; 74 | uint32_t height; 75 | uint16_t planes; 76 | uint16_t bitsperpixel; 77 | uint32_t compression; 78 | uint32_t imagesize; 79 | uint32_t ypixelpermeter; 80 | uint32_t xpixelpermeter; 81 | uint32_t numcolorspallette; 82 | uint32_t mostimpcolor; 83 | } bitmapinfoheader; 84 | typedef struct { 85 | fileheader fileheader; 86 | bitmapinfoheader bitmapinfoheader; 87 | } bitmap; 88 | #pragma pack(pop) 89 | 90 | typedef struct { 91 | uint32_t width; 92 | uint32_t height; 93 | uint8_t bbp; 94 | uint8_t *pixelbuffer; 95 | } rend_t; 96 | 97 | #define _planes 1 98 | #define _compression 0 99 | #define _xpixelpermeter 0x130B //2835 , 72 DPI 100 | #define _ypixelpermeter 0x130B //2835 , 72 DPI 101 | 102 | //========================================================================= 103 | void get_hi_bmp(BITMAP_S *bmp); 104 | void render_init(uint32_t width, uint32_t height, uint8_t bbp); 105 | void render_deinit(void); 106 | void render_save_bitmap(void); 107 | void render_clear_screen(void); 108 | void render_draw_pixel(uint16_t x, uint16_t y, color_t color); 109 | void render_fill_rect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, color_t color); 110 | void render_set_bound(uint16_t startx, uint16_t starty, uint16_t endx, uint16_t endy); 111 | void render_write_gram(color_t color); 112 | void render_draw_char(uint16_t x, uint16_t y, const font_t *fnt, utf8_t c); 113 | void render_draw_string(uint16_t x, uint16_t y, const font_t *fnt, const char *s); 114 | void render_set_back_color(color_t color); 115 | void render_set_brush_color(color_t color); 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /hitiny/hitiny_ao.c: -------------------------------------------------------------------------------- 1 | #include "hitiny_aio.h" 2 | #include "hitiny_sys.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define MAX_AO_CHN_NUM 1 9 | 10 | static int mpi_ao_dev_fd = -1; 11 | static int mpi_ao_dev_chn_fds[MAX_AO_CHN_NUM + 1]; 12 | 13 | int hitiny_MPI_AO_Init() 14 | { 15 | if (mpi_ao_dev_fd >= 0) return 0; 16 | 17 | mpi_ao_dev_fd = hitiny_open_dev("/dev/ao"); 18 | if (mpi_ao_dev_fd < 0) return mpi_ao_dev_fd; 19 | 20 | unsigned param = 0; 21 | int ret = ioctl(mpi_ao_dev_fd, 0x40045800, ¶m); 22 | if (ret) 23 | { 24 | log_error("ERROR in hitiny_MPI_AO_Init/ioctl 0x40045800, error 0x%08x: %d (%s)\n", ret, errno, strerror(errno)); 25 | return ret; 26 | } 27 | 28 | for (int i = 0; i <= MAX_AO_CHN_NUM; ++i) 29 | { 30 | mpi_ao_dev_chn_fds[i] = -1; 31 | } 32 | 33 | return 0; 34 | } 35 | 36 | void hitiny_MPI_AO_Done() 37 | { 38 | for (int i = 0; i <= MAX_AO_CHN_NUM; ++i) 39 | { 40 | if (mpi_ao_dev_chn_fds[i] >= 0) 41 | { 42 | close(mpi_ao_dev_chn_fds[i]); 43 | mpi_ao_dev_chn_fds[i] = -1; 44 | } 45 | } 46 | 47 | if (mpi_ao_dev_fd >= 0) 48 | { 49 | close(mpi_ao_dev_fd); 50 | mpi_ao_dev_fd = -1; 51 | } 52 | } 53 | 54 | int hitiny_MPI_AO_SetPubAttr(AUDIO_DEV AoDevId, const AIO_ATTR_S *pstAioAttr) 55 | { 56 | if (AoDevId > 0) return 0xA0168001; 57 | 58 | if (mpi_ao_dev_fd < 0) return 0xA0168010; 59 | 60 | return ioctl(mpi_ao_dev_fd, 0x40245801, pstAioAttr); 61 | } 62 | 63 | int hitiny_MPI_AO_Enable(AUDIO_DEV AoDevId) 64 | { 65 | if (AoDevId > 0) return 0xA0168001; 66 | 67 | if (mpi_ao_dev_fd < 0) return 0xA0168010; 68 | 69 | return ioctl(mpi_ao_dev_fd, 0x5803); 70 | } 71 | 72 | int hitiny_MPI_AO_Disable(AUDIO_DEV AoDevId) 73 | { 74 | if (AoDevId > 0) return 0xA0168001; 75 | 76 | if (mpi_ao_dev_fd < 0) return 0xA0168010; 77 | 78 | return ioctl(mpi_ao_dev_fd, 0x5804); 79 | } 80 | 81 | int hitiny_MPI_AO_EnableChn(AUDIO_DEV AoDevId, AO_CHN AoChn) 82 | { 83 | int fd = hitiny_MPI_AO_GetFd(AoDevId, AoChn); 84 | if (fd <= 0) return fd; 85 | 86 | return ioctl(fd, 0x5808); 87 | } 88 | 89 | int hitiny_MPI_AO_DisableChn(AUDIO_DEV AoDevId, AO_CHN AoChn) 90 | { 91 | int fd = hitiny_MPI_AO_GetFd(AoDevId, AoChn); 92 | if (fd <= 0) return fd; 93 | 94 | return ioctl(fd, 0x5809); 95 | } 96 | 97 | int hitiny_MPI_AO_GetFd(AUDIO_DEV AoDevId, AO_CHN AoChn) 98 | { 99 | if (AoDevId > 0) return 0xA0168001; 100 | 101 | if (AoChn > MAX_AO_CHN_NUM) return 0xA0168002; 102 | 103 | int fd = mpi_ao_dev_chn_fds[AoChn]; 104 | if (fd > 0) return fd; 105 | 106 | fd = hitiny_open_dev("/dev/ao"); 107 | if (fd < 0) return fd; 108 | 109 | unsigned param = AoChn; 110 | int ret = ioctl(fd, 0x40045800, ¶m); 111 | if (ret) 112 | { 113 | log_error("ERROR in hitiny_MPI_AO_GetFd/ioctl 0x40045800, error 0x%08x: %d (%s)\n", ret, errno, strerror(errno)); 114 | close(fd); 115 | return ret; 116 | } 117 | 118 | mpi_ao_dev_chn_fds[AoChn] = fd; 119 | 120 | return fd; 121 | } 122 | 123 | int hitiny_MPI_AO_SendFrame(AUDIO_DEV AudioDevId, AO_CHN AoChn, const AUDIO_FRAME_S* frame, HI_BOOL blocking_mode) 124 | { 125 | int fd = hitiny_MPI_AO_GetFd(AudioDevId, AoChn); 126 | 127 | if (fd <= 0) return fd; 128 | 129 | if (!blocking_mode) 130 | { 131 | struct pollfd x; 132 | x.fd = fd; 133 | x.events = POLLOUT; 134 | poll(&x, 1, 0); 135 | if (x.events != POLLOUT) return 0xA016800F; 136 | } 137 | 138 | int result = ioctl(fd, 0x40305805, frame); 139 | 140 | return result; 141 | } 142 | 143 | -------------------------------------------------------------------------------- /jxh42_i2c/jxh42_sensor_ctl.c: -------------------------------------------------------------------------------- 1 | #include 2 | // #include 3 | // #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "hi_i2c.h" 9 | 10 | static int hi_i2c_fd = -1; 11 | 12 | void sensor_hi_i2c_close() 13 | { 14 | if (hi_i2c_fd >=0) 15 | { 16 | close(hi_i2c_fd); 17 | hi_i2c_fd = -1; 18 | } 19 | } 20 | 21 | int sensor_write_register(int addr, int data) 22 | { 23 | int fd = hi_i2c_fd; 24 | if (fd < 0) 25 | { 26 | fd = open("/dev/hi_i2c", 0); 27 | if (fd < 0) 28 | { 29 | fprintf(stderr, "Open /dev/hi_i2c error!"); 30 | return -1; 31 | } 32 | 33 | hi_i2c_fd = fd; 34 | } 35 | 36 | I2C_DATA_S i2c_data; 37 | i2c_data.data = data; 38 | i2c_data.dev_addr = 0x60; 39 | i2c_data.reg_addr = addr; 40 | i2c_data.addr_byte_num = 1; 41 | i2c_data.data_byte_num = 1; 42 | 43 | //fprintf(stderr, "DBG: sensor_write_register(0x%x, 0x%x)\n", i2c_data.reg_addr, i2c_data.data); 44 | 45 | int ret = ioctl(fd, CMD_I2C_WRITE, &i2c_data); 46 | if (ret) 47 | { 48 | fprintf(stderr, "\tERROR write to 0x%x value 0x%x!\n", addr, data); 49 | } 50 | 51 | return ret; 52 | } 53 | 54 | void sensor_init() 55 | { 56 | sensor_write_register(0x12, 0x40); 57 | sensor_write_register(0xD, 0x40); 58 | sensor_write_register(0x1F, 4); 59 | sensor_write_register(0xE, 0x1D); 60 | sensor_write_register(0xF, 9); 61 | sensor_write_register(0x10, 0x1E); 62 | sensor_write_register(0x11, 0x80); 63 | sensor_write_register(0x20, 0x40); 64 | sensor_write_register(0x21, 6); 65 | sensor_write_register(0x22, 0xF0); 66 | sensor_write_register(0x23, 2); 67 | sensor_write_register(0x24, 0); 68 | sensor_write_register(0x25, 0xDC); 69 | sensor_write_register(0x26, 0x25); 70 | sensor_write_register(0x27, 0x3B); 71 | sensor_write_register(0x28, 9); 72 | sensor_write_register(0x29, 1); 73 | sensor_write_register(0x2A, 0x24); 74 | sensor_write_register(0x2B, 0x29); 75 | sensor_write_register(0x2C, 4); 76 | sensor_write_register(0x2D, 0); 77 | sensor_write_register(0x2E, 0xBB); 78 | sensor_write_register(0x2F, 0); 79 | sensor_write_register(0x30, 0x92); 80 | sensor_write_register(0x31, 0xA); 81 | sensor_write_register(0x32, 0xAA); 82 | sensor_write_register(0x33, 0x14); 83 | sensor_write_register(0x34, 0x38); 84 | sensor_write_register(0x35, 0x54); 85 | sensor_write_register(0x42, 0x41); 86 | sensor_write_register(0x43, 0x50); 87 | sensor_write_register(0x1D, 0xFF); 88 | sensor_write_register(0x1E, 0x9F); 89 | sensor_write_register(0x6C, 0x90); 90 | sensor_write_register(0x73, 0xB3); 91 | sensor_write_register(0x70, 0x68); 92 | sensor_write_register(0x76, 0x40); 93 | sensor_write_register(0x77, 6); 94 | sensor_write_register(0x60, 0xA4); 95 | sensor_write_register(0x61, 0xFF); 96 | sensor_write_register(0x62, 0x40); 97 | sensor_write_register(0x63, 0x51); 98 | sensor_write_register(0x65, 0); 99 | sensor_write_register(0x66, 0x20); 100 | sensor_write_register(0x67, 0x30); 101 | sensor_write_register(0x68, 4); 102 | sensor_write_register(0x69, 0x74); 103 | sensor_write_register(0x6A, 9); 104 | sensor_write_register(0x6F, 4); 105 | sensor_write_register(0x13, 0x87); 106 | sensor_write_register(0x14, 0x80); 107 | sensor_write_register(0x16, 0xC0); 108 | sensor_write_register(0x17, 0x40); 109 | sensor_write_register(0x18, 0xE1); 110 | sensor_write_register(0x38, 0x38); 111 | sensor_write_register(0x39, 0x92); 112 | sensor_write_register(0x4A, 3); 113 | sensor_write_register(0x48, 0x40); 114 | sensor_write_register(0x49, 4); 115 | sensor_write_register(0xD, 0x40); 116 | sensor_write_register(0x12, 0); 117 | puts("soih42 sensor 720p init success!"); 118 | } 119 | 120 | -------------------------------------------------------------------------------- /tools/hi_vireg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | unsigned read_mem_reg(uint32_t addr) { 14 | static int mem_fd; 15 | static char *loaded_area; 16 | static uint32_t loaded_offset; 17 | static uint32_t loaded_size; 18 | 19 | uint32_t offset = addr & 0xffff0000; 20 | uint32_t size = 0xffff; 21 | if (!addr || (loaded_area && offset != loaded_offset)) { 22 | int res = munmap(loaded_area, loaded_size); 23 | if (res) { 24 | fprintf(stderr, "read_mem_reg error: %s (%d)\n", strerror(errno), errno); 25 | } 26 | } 27 | 28 | if (!addr) { 29 | close(mem_fd); 30 | return true; 31 | } 32 | 33 | if (!mem_fd) { 34 | mem_fd = open("/dev/mem", O_RDWR | O_SYNC); 35 | if (mem_fd < 0) { 36 | fprintf(stderr, "can't open /dev/mem\n"); 37 | return false; 38 | } 39 | } 40 | 41 | volatile char *mapped_area; 42 | if (offset != loaded_offset) { 43 | mapped_area = 44 | mmap(NULL, // Any adddress in our space will do 45 | size, // Map length 46 | PROT_READ | PROT_WRITE, // Enable reading & writting to mapped memory 47 | MAP_SHARED, // Shared with other processes 48 | mem_fd, // File to map 49 | offset // Offset to base address 50 | ); 51 | if (mapped_area == MAP_FAILED) { 52 | fprintf(stderr, "read_mem_reg mmap error: %s (%d)\n", 53 | strerror(errno), errno); 54 | return false; 55 | } 56 | loaded_area = (char *)mapped_area; 57 | loaded_size = size; 58 | loaded_offset = offset; 59 | } else 60 | mapped_area = loaded_area; 61 | 62 | unsigned data = *(volatile uint32_t *)(mapped_area + (addr - offset)); 63 | 64 | return data; 65 | } 66 | 67 | 68 | int main(int argc, char** argv) 69 | { 70 | printf("PT_INTF_MOD\t = 0x%08x\n", read_mem_reg(0x20580100)); 71 | printf("PT_BT656_CFG\t = 0x%08x\n", read_mem_reg(0x20580120)); 72 | printf("PT_UNIFY_TIMING_CFG\t = 0x%08x\n", read_mem_reg(0x20580130)); 73 | printf("PT_GEN_TIMING_CFG\t = 0x%08x\n", read_mem_reg(0x20580134)); 74 | printf("PT_INTF_HFB\t = 0x%08x\n", read_mem_reg(0x20580180)); 75 | printf("PT_INTF_HACT\t = 0x%08x\n", read_mem_reg(0x20580184)); 76 | printf("PT_INTF_HBB\t = 0x%08x\n", read_mem_reg(0x20580188)); 77 | printf("PT_INTF_VFB\t = 0x%08x\n", read_mem_reg(0x2058018c)); 78 | printf("PT_INTF_VACT\t = 0x%08x\n", read_mem_reg(0x20580190)); 79 | printf("PT_INTF_VBB\t = 0x%08x\n", read_mem_reg(0x20580194)); 80 | printf("PT_INTF_VBFB\t = 0x%08x\n", read_mem_reg(0x20580198)); 81 | printf("PT_INTF_VBACT\t = 0x%08x\n", read_mem_reg(0x2058019c)); 82 | printf("PT_INTF_VBBB\t = 0x%08x\n", read_mem_reg(0x205801a0)); 83 | printf("PT_FLASH_CFG\t = 0x%08x\n", read_mem_reg(0x205801b0)); 84 | printf("PT_FLASH_CYC0\t = 0x%08x\n", read_mem_reg(0x205801c0)); 85 | printf("PT_FLASH_CYC1\t = 0x%08x\n", read_mem_reg(0x205801c4)); 86 | printf("PT_SHUTTER_CYC0\t = 0x%08x\n", read_mem_reg(0x205801d0)); 87 | printf("PT_SHUTTER_CYC1\t = 0x%08x\n", read_mem_reg(0x205801d4)); 88 | printf("PT_SHUTTER_CYC2\t = 0x%08x\n", read_mem_reg(0x205801d8)); 89 | printf("PT_SHUTTER_CYC3\t = 0x%08x\n", read_mem_reg(0x205801d3)); 90 | printf("PT_STATUS\t = 0x%08x\n", read_mem_reg(0x205801e0)); 91 | printf("PT_BT656_STATUS\t = 0x%08x\n", read_mem_reg(0x205801e4)); 92 | // printf("\t = 0x%08x\n", read_mem_reg(0x20580xxx)); 93 | // printf("\t = 0x%08x\n", read_mem_reg(0x20580xxx)); 94 | // printf("\t = 0x%08x\n", read_mem_reg(0x20580xxx)); 95 | 96 | 97 | } 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /hitiny/hitiny_vi.c: -------------------------------------------------------------------------------- 1 | #include "hitiny_vi.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static int g_hitiny_fd_vi[VIU_MAX_CHN_NUM] = { -1 }; 11 | 12 | void hitiny_MPI_VI_Init() 13 | { 14 | for (unsigned i = 0; i < VIU_MAX_CHN_NUM; i++) 15 | { 16 | g_hitiny_fd_vi[i] = -1; 17 | } 18 | } 19 | 20 | void hitiny_MPI_VI_Done() 21 | { 22 | for (unsigned i = 0; i < VIU_MAX_CHN_NUM; i++) 23 | { 24 | if (g_hitiny_fd_vi[i] >= 0) 25 | { 26 | close(g_hitiny_fd_vi[i]); 27 | g_hitiny_fd_vi[i] = -1; 28 | } 29 | } 30 | } 31 | 32 | int open_vi_chn_fd(VI_CHN ViChn) 33 | { 34 | char fname[32]; 35 | struct stat stat_buf; 36 | snprintf(fname, 32, "/dev/vi"); 37 | if (stat(fname, &stat_buf) < 0) 38 | { 39 | log_error("ERROR: can't stat() on '%s', %d (%s)", fname, errno, strerror(errno)); 40 | return -1; 41 | } 42 | 43 | if ((stat_buf.st_mode & 0xF000) != 0x2000) 44 | { 45 | log_error("ERROR: %s is not a device", fname); 46 | return -1; 47 | } 48 | 49 | int _new_chn_fd = open(fname, 2, 0); 50 | if (_new_chn_fd < 0) 51 | { 52 | log_error("ERROR: can't open() on '%s', %d (%s)", fname, errno, strerror(errno)); 53 | return -1; 54 | } 55 | 56 | unsigned req_data = ViChn; 57 | if (ioctl(_new_chn_fd, 0x40044923, &req_data)) 58 | { 59 | close(_new_chn_fd); 60 | log_error("ERROR: can't ioctl(0x40044923) for vi channel %u", ViChn); 61 | 62 | return -1; 63 | } 64 | 65 | return _new_chn_fd; 66 | 67 | } 68 | 69 | int hitiny_MPI_VI_GetFd(VI_CHN ViChn) 70 | { 71 | if (ViChn >= VIU_MAX_CHN_NUM) return 0xA0108002; 72 | 73 | int fd = g_hitiny_fd_vi[ViChn]; 74 | 75 | if (fd < 0) 76 | { 77 | fd = open_vi_chn_fd(ViChn); 78 | g_hitiny_fd_vi[ViChn] = fd; 79 | 80 | if (-1 == fd) 81 | { 82 | return 0xA0108010; 83 | } 84 | } 85 | 86 | return fd; 87 | } 88 | 89 | int hitiny_MPI_VI_SetExtChnAttr(VI_CHN ViChn, const VI_EXT_CHN_ATTR_S *pstExtChnAttr) 90 | { 91 | int fd = hitiny_MPI_VI_GetFd(ViChn); 92 | 93 | if (fd < 0) return fd; 94 | 95 | return ioctl(fd, 0x40184930, pstExtChnAttr); 96 | } 97 | 98 | int hitiny_MPI_VI_EnableChn(VI_CHN ViChn) 99 | { 100 | int fd = hitiny_MPI_VI_GetFd(ViChn); 101 | 102 | if (fd < 0) return fd; 103 | 104 | return ioctl(fd, 0x490e); 105 | } 106 | 107 | int hitiny_MPI_VI_DisableChn(VI_CHN ViChn) 108 | { 109 | int fd = hitiny_MPI_VI_GetFd(ViChn); 110 | 111 | if (fd < 0) return fd; 112 | 113 | return ioctl(fd, 0x490f); 114 | } 115 | 116 | int hitiny_MPI_VI_GetFrame(VI_CHN ViChn, VIDEO_FRAME_INFO_S *pstFrameInfo) 117 | { 118 | int fd = hitiny_MPI_VI_GetFd(ViChn); 119 | 120 | if (fd < 0) return fd; 121 | 122 | return ioctl(fd, 0x80584914, pstFrameInfo); 123 | } 124 | 125 | int hitiny_MPI_VI_GetFrameTimeOut(VI_CHN ViChn, VIDEO_FRAME_INFO_S *pstFrameInfo, unsigned u32MilliSec) 126 | { 127 | return -13; 128 | } 129 | 130 | int hitiny_MPI_VI_ReleaseFrame(VI_CHN ViChn, VIDEO_FRAME_INFO_S *pstFrameInfo) 131 | { 132 | int fd = hitiny_MPI_VI_GetFd(ViChn); 133 | 134 | if (fd < 0) return fd; 135 | 136 | return ioctl(fd, 0x40584916, pstFrameInfo); 137 | } 138 | 139 | int hitiny_MPI_VI_SetFrameDepth(VI_CHN ViChn, unsigned u32Depth) 140 | { 141 | int fd = hitiny_MPI_VI_GetFd(ViChn); 142 | 143 | if (fd < 0) return fd; 144 | 145 | unsigned param = u32Depth; 146 | 147 | return ioctl(fd, 0x40044912, ¶m); 148 | } 149 | 150 | int hitiny_MPI_VI_GetFrameDepth(VI_CHN ViChn, unsigned *pu32Depth) 151 | { 152 | if (!pu32Depth) return 0xA0108006; 153 | 154 | int fd = hitiny_MPI_VI_GetFd(ViChn); 155 | 156 | if (fd < 0) return fd; 157 | 158 | return ioctl(fd, 0xC0044913, pu32Depth); 159 | } 160 | 161 | 162 | -------------------------------------------------------------------------------- /aux/logger.h: -------------------------------------------------------------------------------- 1 | #ifndef __AUX_LOGGER_H__ 2 | #define __AUX_LOGGER_H__ 3 | 4 | #include 5 | #include 6 | #include "gmtime.h" 7 | #include "system.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #define LOG_access 0 /* ACC: special level for access log */ 14 | #define LOG_emerg 1 /* EME: system is unusable */ 15 | #define LOG_alert 2 /* ALE: action must be taken immediately */ 16 | #define LOG_crit 3 /* CRI: critical conditions */ 17 | #define LOG_error 4 /* ERR: error conditions */ 18 | #define LOG_warn 5 /* WRN: warning conditions */ 19 | #define LOG_notice 6 /* NOT: normal, but significant condition */ 20 | #define LOG_info 7 /* NFO: informational message */ 21 | #define LOG_debug 8 /* DBG: debug message */ 22 | 23 | #define log_msg(lev,fmt,...) log_fmt(stderr,LOG_##lev,#lev,fmt,##__VA_ARGS__) 24 | #define log_err(err,fmt,...) log_msg(error, fmt " (%d: %s)\n", ##__VA_ARGS__, err, aux_strerror(err)) 25 | #define log_ret(err,fmt,...) log_msg(error, fmt " (%d: %s)\n", ##__VA_ARGS__, err, aux_strerror(err)), err 26 | #define log_die(err,fmt,...) log_msg(emerg, fmt " (%d: %s)\n", ##__VA_ARGS__, err, aux_strerror(err)); exit(EXIT_FAILURE) 27 | 28 | #define std_msg(fmt,...) fprintf(stderr,fmt "\n", ##__VA_ARGS__) 29 | #define std_err(err,fmt,...) fprintf(stderr,fmt " (%d: %s)\n", ##__VA_ARGS__, err, aux_strerror(err)) 30 | #define std_ret(err,fmt,...) fprintf(stderr,fmt " (%d: %s)\n", ##__VA_ARGS__, err, aux_strerror(err)), err 31 | #define std_die(err,fmt,...) fprintf(stderr,fmt " (%d: %s)\n", ##__VA_ARGS__, err, aux_strerror(err)); exit(EXIT_FAILURE) 32 | 33 | #define log_access( fmt,...) log_msg(access,fmt,##__VA_ARGS__) 34 | #define log_emerg( fmt,...) log_msg(emerg, fmt,##__VA_ARGS__) 35 | #define log_alert( fmt,...) log_msg(alert, fmt,##__VA_ARGS__) 36 | #define log_crit( fmt,...) log_msg(crit, fmt,##__VA_ARGS__) 37 | #define log_error( fmt,...) log_msg(error, fmt,##__VA_ARGS__) 38 | #define log_warn( fmt,...) log_msg(warn, fmt,##__VA_ARGS__) 39 | #define log_notice( fmt,...) log_msg(notice,fmt,##__VA_ARGS__) 40 | #define log_info( fmt,...) log_msg(info, fmt,##__VA_ARGS__) 41 | #ifndef NDEBUG 42 | #define log_debug( fmt,...) log_msg(debug, fmt,##__VA_ARGS__) 43 | #else 44 | #define log_debug( fmt,...) /* nothing here */ 45 | #endif /* NDEBUG */ 46 | 47 | #define LOG_FORMAT(lvstr,fmt) "%04u-%02u-%02u %02u:%02u:%02u.%03u " lvstr " " fmt "\n" 48 | #define LOG_VALUES(tmloc,tv,...) tmloc.tm_year + 1900, tmloc.tm_mon + 1, tmloc.tm_mday, \ 49 | tmloc.tm_hour, tmloc.tm_min, tmloc.tm_sec, (unsigned) tv.tv_usec / 1000, ##__VA_ARGS__ 50 | 51 | #define log_fmt(fp,level,lvstr,fmt,...) do { \ 52 | \ 53 | if (level <= log_level) \ 54 | { \ 55 | struct tm tmloc; \ 56 | struct timeval tv; \ 57 | gettimeofday(&tv, NULL); \ 58 | localtime_r(&tv.tv_sec, &tmloc); \ 59 | \ 60 | fprintf(fp, LOG_FORMAT(lvstr,fmt), \ 61 | LOG_VALUES(tmloc,tv,##__VA_ARGS__)); \ 62 | } \ 63 | \ 64 | } while (0) 65 | 66 | extern volatile int log_level; 67 | int log_levels(const char* level); 68 | int log_create(const char* path, int level); 69 | 70 | #define log_create_from_str(path, level) log_create(path, log_levels(level)) 71 | #define log_rotate(path) log_create(path, log_level) 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif /* __AUX_LOGGER_H__ */ 78 | -------------------------------------------------------------------------------- /libev/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the `clock_gettime' function. */ 5 | #define HAVE_CLOCK_GETTIME 1 6 | 7 | /* Define to 1 to use the syscall interface for clock_gettime */ 8 | /* #undef HAVE_CLOCK_SYSCALL */ 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_DLFCN_H 1 12 | 13 | /* Define to 1 if you have the `epoll_ctl' function. */ 14 | #define HAVE_EPOLL_CTL 1 15 | 16 | /* Define to 1 if you have the `eventfd' function. */ 17 | #define HAVE_EVENTFD 1 18 | 19 | /* Define to 1 if the floor function is available */ 20 | #define HAVE_FLOOR 1 21 | 22 | /* Define to 1 if you have the `inotify_init' function. */ 23 | #define HAVE_INOTIFY_INIT 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_INTTYPES_H 1 27 | 28 | /* Define to 1 if you have the `kqueue' function. */ 29 | /* #undef HAVE_KQUEUE */ 30 | 31 | /* Define to 1 if you have the `rt' library (-lrt). */ 32 | /* #undef HAVE_LIBRT */ 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_MEMORY_H 1 36 | 37 | /* Define to 1 if you have the `nanosleep' function. */ 38 | #define HAVE_NANOSLEEP 1 39 | 40 | /* Define to 1 if you have the `poll' function. */ 41 | #define HAVE_POLL 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_POLL_H 1 45 | 46 | /* Define to 1 if you have the `port_create' function. */ 47 | /* #undef HAVE_PORT_CREATE */ 48 | 49 | /* Define to 1 if you have the header file. */ 50 | /* #undef HAVE_PORT_H */ 51 | 52 | /* Define to 1 if you have the `select' function. */ 53 | #define HAVE_SELECT 1 54 | 55 | /* Define to 1 if you have the `signalfd' function. */ 56 | #define HAVE_SIGNALFD 1 57 | 58 | /* Define to 1 if you have the header file. */ 59 | #define HAVE_STDINT_H 1 60 | 61 | /* Define to 1 if you have the header file. */ 62 | #define HAVE_STDLIB_H 1 63 | 64 | /* Define to 1 if you have the header file. */ 65 | #define HAVE_STRINGS_H 1 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #define HAVE_STRING_H 1 69 | 70 | /* Define to 1 if you have the header file. */ 71 | #define HAVE_SYS_EPOLL_H 1 72 | 73 | /* Define to 1 if you have the header file. */ 74 | #define HAVE_SYS_EVENTFD_H 1 75 | 76 | /* Define to 1 if you have the header file. */ 77 | /* #undef HAVE_SYS_EVENT_H */ 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #define HAVE_SYS_INOTIFY_H 1 81 | 82 | /* Define to 1 if you have the header file. */ 83 | #define HAVE_SYS_SELECT_H 1 84 | 85 | /* Define to 1 if you have the header file. */ 86 | #define HAVE_SYS_SIGNALFD_H 1 87 | 88 | /* Define to 1 if you have the header file. */ 89 | #define HAVE_SYS_STAT_H 1 90 | 91 | /* Define to 1 if you have the header file. */ 92 | #define HAVE_SYS_TYPES_H 1 93 | 94 | /* Define to 1 if you have the header file. */ 95 | #define HAVE_UNISTD_H 1 96 | 97 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 98 | */ 99 | #define LT_OBJDIR ".libs/" 100 | 101 | /* Name of package */ 102 | #define PACKAGE "libev" 103 | 104 | /* Define to the address where bug reports for this package should be sent. */ 105 | #define PACKAGE_BUGREPORT "" 106 | 107 | /* Define to the full name of this package. */ 108 | #define PACKAGE_NAME "" 109 | 110 | /* Define to the full name and version of this package. */ 111 | #define PACKAGE_STRING "" 112 | 113 | /* Define to the one symbol short name of this package. */ 114 | #define PACKAGE_TARNAME "" 115 | 116 | /* Define to the home page for this package. */ 117 | #define PACKAGE_URL "" 118 | 119 | /* Define to the version of this package. */ 120 | #define PACKAGE_VERSION "" 121 | 122 | /* Define to 1 if you have the ANSI C header files. */ 123 | #define STDC_HEADERS 1 124 | 125 | /* Version number of package */ 126 | #define VERSION "4.22" 127 | -------------------------------------------------------------------------------- /cmake/Modules/FindHiSiliconSDK.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find HiSiliconSDK 2 | # Once done this will define 3 | # VENDOR_SDK_FOUND - System has HiSilicon SDK 4 | # VENDOR_SDK_INCLUDE_DIRS - The HiSilicon SDK include directories 5 | # VENDOR_SDK_LIBRARIES - The libraries needed to use HiSilicon SDK 6 | 7 | find_path(VENDOR_SDK_INCLUDE_DIRS hi_common.h 8 | HINTS ${PLATFORM_SDK_DIR} 9 | PATH_SUFFIXES mpp2/include mpp/include include source/gmp/include 10 | REQUIRED 11 | NO_CMAKE_FIND_ROOT_PATH 12 | ) 13 | 14 | execute_process(COMMAND ${CMAKE_CURRENT_LIST_DIR}/get_hisisdk_ver.py 15 | ${VENDOR_SDK_INCLUDE_DIRS}/.. 16 | OUTPUT_VARIABLE RAW_SDK_VER 17 | ) 18 | if(RAW_SDK_VER) 19 | list(GET RAW_SDK_VER 0 HISILICON_SDK_CODE) 20 | list(GET RAW_SDK_VER 1 HISILICON_SDK_FAMILY) 21 | list(GET RAW_SDK_VER 2 HISILICON_SDK_VERSION_MAJOR) 22 | list(GET RAW_SDK_VER 3 HISILICON_SDK_VERSION_MINOR) 23 | list(GET RAW_SDK_VER 4 HISILICON_SDK_VERSION_PATCH) 24 | list(GET RAW_SDK_VER 5 HISILICON_SDK_VERSION_TWEAK) 25 | list(GET RAW_SDK_VER 7 HISILICON_SDK_VERSION_DATE) 26 | list(SUBLIST RAW_SDK_VER 2 5 SDK_ONLY_VER) 27 | list(JOIN SDK_ONLY_VER "." HISILICON_SDK_VERSION) 28 | message("Detected ${HISILICON_SDK_FAMILY} SDK version ${HISILICON_SDK_VERSION}") 29 | set(VENDOR_SDK_FOUND 1) 30 | else() 31 | message(FATAL_ERROR "No HiSilicon SDK detected") 32 | endif() 33 | add_compile_definitions(HISILICON_SDK_CODE=0x${HISILICON_SDK_CODE}) 34 | add_compile_definitions(HISILICON_SDK_FAMILY="${HISILICON_SDK_FAMILY}") 35 | add_compile_definitions(HISILICON_SDK_VERSION="${HISILICON_SDK_VERSION}") 36 | 37 | if(HISILICON_SDK_CODE STREQUAL "3516C500") 38 | add_compile_definitions(MAX_VIDEO_CHANNELS=3) 39 | endif() 40 | 41 | if(HISILICON_SDK_CODE STREQUAL "7205200") 42 | set(CORE_LIBS_NAMES 43 | hi_mpi 44 | hi_md # Motion detection 45 | hi_isp # Image signal processor 46 | hi_ive # Intelligent video engine 47 | hi_ae 48 | hi_awb 49 | 50 | gk_ae 51 | gk_api 52 | gk_awb 53 | gk_awb_natura 54 | gk_bcd 55 | gk_cipher 56 | gk_isp 57 | gk_ive 58 | gk_ivp 59 | gk_md 60 | gk_qr 61 | gk_tde 62 | 63 | securec # Secure C functions 64 | upvqe # Up voice quality enhancement 65 | dnvqe # Down voice quality enhancement 66 | voice_engine 67 | ldci 68 | dehaze # Remove haze 69 | drc # Dynamic range compression 70 | ir_auto # IR Cut auto 71 | ) 72 | else() 73 | 74 | if(HISILICON_SDK_CODE STREQUAL "3518") 75 | set(SPECIFIC_LIBS 76 | resampler 77 | aec 78 | anr 79 | vqev2 80 | ) 81 | endif() 82 | 83 | set(CORE_LIBS_NAMES 84 | mpi 85 | md # Motion detection 86 | _hiae # Automatic exposure 87 | isp # Image signal processor 88 | ive # Intelligent video engine 89 | _hidehaze # Remove haze 90 | _hidefog # Remove fog 91 | _hidrc # Dynamic range compression 92 | _hildci # LDCI/Sharpen 93 | _hiawb # Automatic white balance 94 | _hiir_auto # IR Cut auto 95 | _hiaf # Automatic focus 96 | _hiacs 97 | _hicalcflicker # Flicker calculations 98 | upvqe # Up voice quality enhancement 99 | dnvqe # Down voice quality enhancement 100 | securec # Secure C functions 101 | VoiceEngine 102 | ${SPECIFIC_LIBS} 103 | ) 104 | endif() 105 | 106 | foreach(LIB ${CORE_LIBS_NAMES}) 107 | find_library(FOUND_LIB_${LIB} ${LIB} 108 | PATH_SUFFIXES mpp2/lib mpp/lib lib 109 | source/gmp/lib source/gmp/lib_log/static 110 | HINTS ${PLATFORM_SDK_DIR} 111 | NO_CMAKE_FIND_ROOT_PATH 112 | ) 113 | if(FOUND_LIB_${LIB}) 114 | list(APPEND CORE_LIBS ${FOUND_LIB_${LIB}}) 115 | endif() 116 | message("Lib: ${LIB}") 117 | message("Found Lib: ${FOUND_LIB_${LIB}}") 118 | endforeach(LIB) 119 | 120 | set(VENDOR_SDK_LIBRARIES 121 | ${CORE_LIBS} 122 | ) 123 | -------------------------------------------------------------------------------- /tools/histodiffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "hi_common.h" 13 | #include "hi_comm_video.h" 14 | #include "hi_comm_sys.h" 15 | #include "hi_comm_vb.h" 16 | #include "hi_comm_vi.h" 17 | #include 18 | #include 19 | 20 | #define MAX_FRM_CNT 256 21 | #define MAX_FRM_WIDTH 4096 22 | 23 | #define IVE_HIST_SZ 1024 24 | 25 | unsigned cur_hist_buf = 0; 26 | IVE_MEM_INFO_S stHist[2]; 27 | void *pVirHist[2] = { 0 }; 28 | unsigned NORMA; 29 | 30 | unsigned DIFF() 31 | { 32 | unsigned* b0 = (unsigned*)(pVirHist[0]); 33 | unsigned* b1 = (unsigned*)(pVirHist[1]); 34 | 35 | unsigned sum = 0; 36 | 37 | for (unsigned i = 0; i < 256; ++i) 38 | { 39 | int delta = b0[i] - b1[i]; 40 | if (delta < 0) delta = -delta; 41 | 42 | sum += delta * i; 43 | } 44 | 45 | return sum / NORMA; 46 | } 47 | 48 | void hist_buf_init(const IVE_SRC_INFO_S* src) 49 | { 50 | int s32Ret = hitiny_MPI_SYS_MmzAlloc(&(stHist[cur_hist_buf].u32PhyAddr), &(pVirHist[cur_hist_buf]), "tester", HI_NULL, IVE_HIST_SZ); 51 | if (s32Ret != HI_SUCCESS) 52 | { 53 | fprintf(stderr, "alloc hist mem error: 0x%x\n", s32Ret); 54 | exit(-1); 55 | } 56 | 57 | stHist[cur_hist_buf].u32Stride = src->u32Width; 58 | NORMA = src->u32Width * src->u32Height; 59 | } 60 | 61 | int do_hist(IVE_SRC_INFO_S* src) 62 | { 63 | if (!pVirHist[cur_hist_buf]) hist_buf_init(src); 64 | 65 | HI_BOOL bFinished; 66 | IVE_HANDLE IveHandleHIST; 67 | int s32Ret = hitiny_MPI_IVE_HIST(&IveHandleHIST, src, &(stHist[cur_hist_buf]), HI_TRUE); 68 | if (s32Ret != HI_SUCCESS) 69 | { 70 | fprintf(stderr, "ive hist create err 0x%x\n", s32Ret); 71 | exit(-1); 72 | } 73 | 74 | printf("now QUERY hist\n"); 75 | s32Ret = hitiny_MPI_IVE_Query(IveHandleHIST, &bFinished, HI_TRUE); 76 | if (s32Ret != HI_SUCCESS) 77 | { 78 | fprintf(stderr, "ive query (hist) err 0x%x\n", s32Ret); 79 | exit(-1); 80 | } 81 | 82 | if (!bFinished) return -1; 83 | 84 | return 0; 85 | } 86 | 87 | void hist_buf_done() 88 | { 89 | hitiny_MPI_SYS_MmzFree(stHist[0].u32PhyAddr, pVirHist[0]); 90 | pVirHist[0] = 0; 91 | hitiny_MPI_SYS_MmzFree(stHist[1].u32PhyAddr, pVirHist[1]); 92 | pVirHist[1] = 0; 93 | } 94 | 95 | HI_S32 do_process_vi(VI_CHN ViChn) 96 | { 97 | usleep(5000); 98 | 99 | VIDEO_FRAME_INFO_S stFrame; 100 | int err = hitiny_MPI_VI_GetFrame(ViChn, &stFrame); 101 | 102 | if (err) 103 | { 104 | printf("hitiny_MPI_VI_GetFrame err, vi chn %d: %08X \n", ViChn, err); 105 | return -1; 106 | } 107 | 108 | 109 | IVE_SRC_INFO_S srcmem; 110 | srcmem.enSrcFmt = IVE_SRC_FMT_SINGLE; 111 | srcmem.stSrcMem.u32PhyAddr = stFrame.stVFrame.u32PhyAddr[0]; 112 | srcmem.stSrcMem.u32Stride = stFrame.stVFrame.u32Stride[0]; 113 | srcmem.u32Width = stFrame.stVFrame.u32Width; 114 | srcmem.u32Height = stFrame.stVFrame.u32Height; 115 | do_hist(&srcmem); 116 | 117 | hitiny_MPI_VI_ReleaseFrame(ViChn, &stFrame); 118 | 119 | return 0; 120 | } 121 | 122 | HI_S32 main(int argc, char *argv[]) 123 | { 124 | if (argc < 2) 125 | { 126 | fprintf(stderr, "Usage: %s VI_CHN\n", argv[0]); 127 | return -1; 128 | } 129 | 130 | VI_CHN ViChn = atoi(argv[1]); 131 | 132 | if (hitiny_MPI_VI_SetFrameDepth(ViChn, 1)) 133 | { 134 | printf("hitiny_MPI_VI_SetFrameDepth err, vi chn %d \n", ViChn); 135 | return -1; 136 | } 137 | 138 | hitiny_MPI_VI_Init(); 139 | 140 | do_process_vi(ViChn); 141 | while (1) 142 | { 143 | cur_hist_buf = (cur_hist_buf + 1) % 2; 144 | do_process_vi(ViChn); 145 | unsigned diff = DIFF(); 146 | printf("DIFF: %u\n", diff); 147 | usleep(1000000); 148 | } 149 | 150 | hitiny_MPI_VI_Done(); 151 | 152 | return 0; 153 | } 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /imx225_i2c/imx225_sensor_ctl.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | 3 | Copyright (C), 2001-2011, Hisilicon Tech. Co., Ltd. 4 | 5 | ****************************************************************************** 6 | File Name : sony225_sensor_ctl.c 7 | Version : Initial Draft 8 | Author : Hisilicon multimedia software group 9 | Created : 2014/11/07 10 | Description : Sony IMX225 sensor driver 11 | History : 12 | 1.Date : 2014/11/07 13 | Author : MPP 14 | Modification: Created file 15 | 16 | ******************************************************************************/ 17 | #include 18 | // #include 19 | // #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "hi_i2c.h" 25 | 26 | int sony_sensor_write_packet(I2C_DATA_S i2c_data) 27 | { 28 | int fd = -1; 29 | int ret; 30 | 31 | fd = open("/dev/hi_i2c", 0); 32 | if(fd < 0) 33 | { 34 | printf("Open /dev/hi_i2c error!\n"); 35 | return -1; 36 | } 37 | 38 | ret = ioctl(fd, CMD_I2C_WRITE, &i2c_data); 39 | 40 | close(fd); 41 | return 0; 42 | } 43 | 44 | 45 | int sensor_write_register(int reg_addr, int reg_value) 46 | { 47 | I2C_DATA_S i2c_data ; 48 | unsigned int reg_width = 2; 49 | unsigned int data_width = 1; 50 | unsigned int device_addr = 0x34; 51 | 52 | i2c_data.dev_addr = device_addr ; 53 | i2c_data.reg_addr = reg_addr ; 54 | i2c_data.addr_byte_num = reg_width ; 55 | i2c_data.data = reg_value ; 56 | i2c_data.data_byte_num = data_width ; 57 | 58 | return sony_sensor_write_packet(i2c_data); 59 | } 60 | 61 | void sensor_prog(int* rom) 62 | { 63 | } 64 | 65 | 66 | void sensor_init() 67 | { 68 | 69 | sensor_write_register(0x3000, 0x01); //Standby 70 | usleep(200000); 71 | 72 | // chip_id = 0x2 73 | sensor_write_register(0x3007, 0x10); //Window mode:720p mode 74 | sensor_write_register(0x3009, 0x01); //30fps mode 75 | sensor_write_register(0x300f, 0x00); 76 | sensor_write_register(0x3012, 0x2c); 77 | sensor_write_register(0x3013, 0x01); 78 | sensor_write_register(0x3016, 0x09); 79 | sensor_write_register(0x3018, 0xee); 80 | sensor_write_register(0x3019, 0x02); 81 | sensor_write_register(0x301b, 0xc8); 82 | sensor_write_register(0x301c, 0x19); 83 | sensor_write_register(0x301d, 0xc2); 84 | sensor_write_register(0x3046, 0x03); 85 | sensor_write_register(0x3047, 0x06); 86 | sensor_write_register(0x3048, 0xc2); 87 | sensor_write_register(0x305c, 0x20); 88 | sensor_write_register(0x305D, 0x00); 89 | sensor_write_register(0x305E, 0x20); 90 | sensor_write_register(0x305F, 0x00); 91 | sensor_write_register(0x3070, 0x02); 92 | sensor_write_register(0x3071, 0x01); 93 | sensor_write_register(0x309E, 0x22); 94 | sensor_write_register(0x30A5, 0xFB); 95 | sensor_write_register(0x30A6, 0x02); 96 | sensor_write_register(0x30B3, 0xFF); 97 | sensor_write_register(0x30B4, 0x01); 98 | sensor_write_register(0x30B5, 0x42); 99 | sensor_write_register(0x30B8, 0x10); 100 | sensor_write_register(0x30C2, 0x01); 101 | 102 | // chip_id = 0x3 103 | sensor_write_register(0x310F, 0x0F); 104 | sensor_write_register(0x3110, 0x0E); 105 | sensor_write_register(0x3111, 0xE7); 106 | sensor_write_register(0x3112, 0x9C); 107 | sensor_write_register(0x3113, 0x83); 108 | sensor_write_register(0x3114, 0x10); 109 | sensor_write_register(0x3115, 0x42); 110 | sensor_write_register(0x3128, 0x1E); 111 | sensor_write_register(0x31ED, 0x38); 112 | 113 | // chip_id = 0x4 114 | sensor_write_register(0x320C, 0xCF); 115 | sensor_write_register(0x324C, 0x40); 116 | sensor_write_register(0x324D, 0x03); 117 | sensor_write_register(0x3261, 0xE0); 118 | sensor_write_register(0x3262, 0x02); 119 | sensor_write_register(0x326E, 0x2F); 120 | sensor_write_register(0x326F, 0x30); 121 | sensor_write_register(0x3270, 0x03); 122 | sensor_write_register(0x3298, 0x00); 123 | sensor_write_register(0x329A, 0x12); 124 | sensor_write_register(0x329B, 0xF1); 125 | sensor_write_register(0x329C, 0x0C); 126 | 127 | usleep(200000); 128 | sensor_write_register(0x3000, 0x00); //release standy 129 | usleep(200000); 130 | sensor_write_register(0x3002, 0x00); //Master mose start 131 | usleep(200000); 132 | sensor_write_register(0x3049, 0x80); //XVS & XHS output 133 | usleep(200000); 134 | 135 | printf("-------Sony IMX225 Sensor Initial OK!-------\n"); 136 | 137 | return ; 138 | 139 | } 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /test/test_ao_tiny.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define AUDIO_PTNUMPERFRM 320 12 | 13 | int stop_flag = 0; 14 | 15 | void action_on_sognal(int signum) 16 | { 17 | log_info("STOP"); 18 | stop_flag = 1; 19 | } 20 | 21 | int hitiny_audio_play_file(FILE* f, int* stop_flag) 22 | { 23 | HI_U32 u32Len = 640; 24 | HI_U32 u32ReadLen; 25 | HI_U8 *pu8AudioStream = NULL; 26 | 27 | pu8AudioStream = (HI_U8*)malloc(sizeof(HI_U8)*MAX_AUDIO_STREAM_LEN); 28 | if (!pu8AudioStream) return -1; 29 | 30 | unsigned id = 0; 31 | 32 | while (!stop_flag || !*stop_flag) 33 | { 34 | u32ReadLen = fread(pu8AudioStream, 1, u32Len, f); 35 | if (u32ReadLen <= 0) 36 | { 37 | free(pu8AudioStream); 38 | return 0; 39 | } 40 | 41 | AUDIO_FRAME_S frame; 42 | frame.enBitwidth = AUDIO_BIT_WIDTH_16; 43 | frame.enSoundmode = AUDIO_SOUND_MODE_MONO; 44 | frame.pVirAddr[0] = pu8AudioStream; 45 | frame.pVirAddr[1] = 0; 46 | frame.u32PhyAddr[0] = 0; 47 | frame.u32PhyAddr[1] = 0; 48 | frame.u64TimeStamp = 0; 49 | frame.u32Seq = id; 50 | frame.u32Len = u32ReadLen; 51 | frame.u32PoolId[0] = 0; 52 | frame.u32PoolId[1] = 0; 53 | 54 | int res = hitiny_MPI_AO_SendFrame(0, 0, &frame, HI_TRUE); 55 | if (res != 0) 56 | { 57 | fprintf(stderr, "hitiny_MPI_AO_SendFrame return: 0x%08x\n", res); 58 | exit(-2); 59 | } 60 | 61 | id++; 62 | } 63 | free(pu8AudioStream); 64 | return 1; 65 | } 66 | 67 | int my_audio_init(int bMic, PAYLOAD_TYPE_E payload_type, int audio_rate) 68 | { 69 | AUDIO_DEV AoDev = 0; 70 | AO_CHN AoChn = 0; 71 | 72 | AIO_ATTR_S stAioAttr; 73 | memset(&stAioAttr, 0, sizeof(AIO_ATTR_S)); 74 | 75 | stAioAttr.enSamplerate = audio_rate; 76 | stAioAttr.enBitwidth = AUDIO_BIT_WIDTH_16; 77 | stAioAttr.enWorkmode = AIO_MODE_I2S_MASTER; 78 | stAioAttr.enSoundmode = AUDIO_SOUND_MODE_MONO; 79 | stAioAttr.u32EXFlag = 1; 80 | stAioAttr.u32FrmNum = 30; 81 | stAioAttr.u32PtNumPerFrm = AUDIO_PTNUMPERFRM; 82 | stAioAttr.u32ChnCnt = 2; 83 | stAioAttr.u32ClkSel = 1; 84 | 85 | int ret = hitiny_MPI_AO_Init(); 86 | if (ret < 0) 87 | { 88 | log_error("hitiny_MPI_AO_Init() failed: 0x%X", ret); 89 | return ret; 90 | } 91 | 92 | ret = hitiny_MPI_AO_Disable(0); 93 | if (ret < 0) 94 | { 95 | log_error("hitiny_MPI_AO_DisableDev: 0x%X", ret); 96 | return ret; 97 | } 98 | 99 | ret = hitiny_MPI_AO_SetPubAttr(0, &stAioAttr); 100 | if (ret < 0) 101 | { 102 | log_error("hitiny_MPI_AO_SetPubAttr failed: 0x%X", ret); 103 | return ret; 104 | } 105 | 106 | ret = hitiny_MPI_AO_Enable(0); 107 | if (ret < 0) 108 | { 109 | log_error("hitiny_MPI_AO_EnableDev: 0x%X", ret); 110 | return ret; 111 | } 112 | 113 | ret = hitiny_MPI_AO_EnableChn(0, 0); 114 | if (ret < 0) 115 | { 116 | log_error("hitiny_MPI_AO_EnableChn: 0x%X", ret); 117 | return ret; 118 | } 119 | 120 | return 0; 121 | } 122 | 123 | 124 | 125 | int main(int argc, char** argv) 126 | { 127 | if (argc < 2) 128 | { 129 | log_error("./test_ao file_to_play.pcm"); 130 | return -1; 131 | 132 | } 133 | 134 | signal(SIGINT, action_on_sognal); 135 | 136 | log_warn("Warning! No SDK version with!"); 137 | 138 | int ret = hitiny_MPI_SYS_Init(); 139 | if (ret < 0) 140 | { 141 | log_error("hitiny_MPI_SYS_Init() failed: 0x%X", ret); 142 | return -1; 143 | } 144 | ret = hitiny_init_acodec(48000, HI_TRUE); 145 | if (ret < 0) 146 | { 147 | log_error("hitiny_init_acodec() failed: 0x%X", ret); 148 | return -1; 149 | } 150 | 151 | ret = my_audio_init(0, PT_LPCM, 48000); 152 | if (ret < 0) 153 | { 154 | log_crit("my_audio_init 0x%X", ret); 155 | return -1; 156 | } 157 | 158 | FILE* f = fopen(argv[1], "r"); 159 | if (f) 160 | { 161 | log_info("Now play %s!", argv[1]); 162 | hitiny_audio_play_file(f, &stop_flag); 163 | fclose(f); 164 | } 165 | else 166 | { 167 | log_error("ERROR %d", errno); 168 | log_error("Error %d: %s", errno, strerror(errno)); 169 | } 170 | 171 | hitiny_MPI_SYS_Done(); 172 | 173 | return 0; 174 | } 175 | 176 | 177 | 178 | 179 | -------------------------------------------------------------------------------- /aux/system.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "logger.h" 6 | #include "system.h" 7 | 8 | int aux_fdopen(int fd, const char *path, int flags) 9 | { 10 | int td; 11 | 12 | td = open(path, flags, 0644); 13 | if (0 > td) return -1; 14 | 15 | return aux_fdmove(td, fd); 16 | } 17 | 18 | 19 | int aux_fdmove(int fd, int nd) /* if nd is ebadf or eq-to-fd => fd is returned */ 20 | { 21 | if (0 > nd || fd == nd) 22 | { 23 | return fd; 24 | } 25 | 26 | nd = dup2(fd, nd); 27 | if (0 > nd) return -1; 28 | 29 | if (0 > close(fd)) 30 | { 31 | return -1; 32 | } 33 | 34 | return nd; 35 | } 36 | 37 | /* 38 | * To pass a BSS-constant, you MUST use char[] (NOT char*) here. 39 | * 40 | * const char rw_access [] = "we can change this string"; 41 | * const char *r_access = "we cannot change this string"; 42 | * 43 | * It's not a hackneyed fact of C (and most likely C++), that static "BSS" 44 | * constants like the second one in the example above MAY be put in read-only 45 | * memory segment by compiler (and gcc have been following that recomendation 46 | * from some release), while the first line in the same example shows the 47 | * string of type, which SHOULD (or MUST, I don't care much) provide write 48 | * permissions if programmer needs it. 49 | * 50 | * The fact, that the const keyword in C does nothing, is much more hackneyed, 51 | * though. 52 | */ 53 | int aux_mkpath(char *path) 54 | { 55 | int rc; 56 | char *p = path + 1; 57 | 58 | for (; *p; ++p) 59 | { 60 | if (*p != '/') continue; 61 | 62 | *p = 0; 63 | rc = mkdir(path, 0755); 64 | *p = '/'; 65 | 66 | if (0 > rc && EEXIST != errno) 67 | { 68 | return -1; 69 | } 70 | } 71 | 72 | return 0; 73 | } 74 | 75 | int aux_mkpidf(const char *path) 76 | { 77 | int fd, nb; 78 | char buf [32]; 79 | 80 | fd = open(path, O_CREAT|O_RDWR, 0644); 81 | if (0 > fd) return -1; 82 | 83 | if (0 > flock(fd, LOCK_EX|LOCK_NB)) 84 | { 85 | log_emerg("can't lock pid-file %s", path); 86 | close(fd); 87 | return -1; 88 | } 89 | 90 | struct stat st; 91 | 92 | if (0 > fstat(fd, &st)) 93 | { 94 | log_emerg("can't stat locked pid-file %s", path); 95 | flock(fd, LOCK_UN); 96 | close(fd); 97 | return -1; 98 | } 99 | 100 | if (st.st_size > 0) 101 | { 102 | log_emerg("pid-file %s exists", path); 103 | flock(fd, LOCK_UN); 104 | close(fd); 105 | return -1; 106 | } 107 | 108 | if (0 > (nb = snprintf(buf, 32, "%d\n", (int) getpid()))) 109 | { 110 | flock(fd, LOCK_UN); 111 | close(fd); 112 | return -1; 113 | } 114 | 115 | if (0 > write(fd, buf, nb)) 116 | { 117 | flock(fd, LOCK_UN); 118 | close(fd); 119 | return -1; 120 | } 121 | 122 | if (0 > flock(fd, LOCK_UN)) 123 | { 124 | close(fd); 125 | return -1; 126 | } 127 | 128 | if (0 > close(fd)) 129 | { 130 | return -1; 131 | } 132 | 133 | return 0; 134 | } 135 | 136 | /* 137 | * In fact, open_flags should be defined by both prot_flags and mmap_flags values, 138 | * and the definition of this interdependence doesn't look trivial sometimes. 139 | * 140 | * However, my guess is that almost in all cases file descriptor must be readable, 141 | * e.g. MAP_SHARED + PROT_WRITE require open with O_RDWR (not O_WRONLY). 142 | * 143 | * See, mmap(2). 144 | */ 145 | int aux_mmap(strp area, int prot_flags, int mmap_flags, const char *filename) 146 | { 147 | int fd; 148 | int open_flags; 149 | 150 | if (NULL == filename) /* MAP_ANONYMOUS */ 151 | { 152 | area->data = mmap(NULL, area->size, prot_flags, 153 | mmap_flags|MAP_ANON, -1, 0); 154 | 155 | if (MAP_FAILED == area->data) return -1; 156 | 157 | return 0; 158 | } 159 | 160 | open_flags = (prot_flags & PROT_WRITE) 161 | ? O_RDWR : O_RDONLY; 162 | 163 | fd = open(filename, open_flags); 164 | if (0 > fd) return -1; 165 | 166 | if (0 != area->size) 167 | { 168 | if (0 > ftruncate(fd, area->size)) 169 | { 170 | close(fd); 171 | return -1; 172 | } 173 | } 174 | else 175 | { 176 | struct stat st; 177 | 178 | if (0 > fstat(fd, &st)) 179 | { 180 | close(fd); 181 | return -1; 182 | } 183 | 184 | area->size = st.st_size; 185 | } 186 | 187 | area->data = mmap(NULL, area->size, prot_flags, 188 | mmap_flags, fd, 0); 189 | 190 | if (MAP_FAILED == area->data) 191 | { 192 | close(fd); 193 | return -1; 194 | } 195 | 196 | if (0 > close(fd)) 197 | { 198 | return -1; 199 | } 200 | 201 | return 0; 202 | } 203 | 204 | -------------------------------------------------------------------------------- /cfg/common.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include 3 | #include 4 | 5 | static unsigned __cfg_proc_line_num = 0; 6 | static unsigned __cfg_proc_line_pos = 0; 7 | 8 | unsigned cfg_proc_err_line_num() 9 | { 10 | return __cfg_proc_line_num; 11 | } 12 | 13 | unsigned cfg_proc_err_line_pos() 14 | { 15 | return __cfg_proc_line_pos; 16 | } 17 | 18 | #define CASE_ERR_MSG(err_code) case err_code: return #err_code; 19 | 20 | const char* cfg_proc_err_msg(int err) 21 | { 22 | switch (err) 23 | { 24 | CASE_ERR_MSG(CFG_PROC_IO) 25 | CASE_ERR_MSG(CFG_PROC_SYNTAX) 26 | CASE_ERR_MSG(CFG_PROC_WRONG_SECTION) 27 | CASE_ERR_MSG(CFG_PROC_KEY_BAD) 28 | CASE_ERR_MSG(CFG_PROC_KEY_DUP) 29 | CASE_ERR_MSG(CFG_PROC_VALUE_BAD) 30 | default: return "UNKNOWN"; 31 | } 32 | } 33 | 34 | static const char* __space_chars = " \t\n\r"; 35 | static const char* __allowed_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_0123456789"; 36 | static const char* __allowed_chars_values = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_0123456789/.|"; 37 | 38 | int cfg_proc_read(const char* fname, cfg_proc_new_section _new_sec, cfg_proc_new_key_value _new_kv) 39 | { 40 | __cfg_proc_line_num = 0; 41 | __cfg_proc_line_pos = 0; 42 | 43 | FILE* f = fopen(fname, "r"); 44 | if (!f) return -1; 45 | 46 | char buf[1024]; 47 | __cfg_proc_line_num = 0; 48 | while (fgets(buf, 1024, f)) 49 | { 50 | __cfg_proc_line_num++; 51 | 52 | char* p = buf; 53 | while (*p && strchr(__space_chars, *p)) ++p; 54 | 55 | if (!*p) continue; 56 | if (*p == ';') continue; 57 | if (*p == '#') continue; 58 | 59 | if ('[' == *p) 60 | { 61 | p++; 62 | char* sec_name = p; 63 | while (*p && strchr(__allowed_chars, *p)) ++p; 64 | if (']' == *p) 65 | { 66 | *p = 0; 67 | if (p == sec_name) 68 | { 69 | fclose(f); 70 | __cfg_proc_line_pos = p - buf + 1; 71 | return CFG_PROC_SYNTAX; 72 | } 73 | int r = _new_sec(sec_name); 74 | if (r < 0) 75 | { 76 | fclose(f); 77 | __cfg_proc_line_pos = sec_name - buf + 1; 78 | return r; 79 | } 80 | p++; 81 | } 82 | else 83 | { 84 | fclose(f); 85 | __cfg_proc_line_pos = p - buf + 1; 86 | return CFG_PROC_SYNTAX; 87 | } 88 | 89 | while (*p && strchr(__space_chars, *p)) ++p; 90 | if (!*p) continue; 91 | if (*p == ';') continue; 92 | if (*p == '#') continue; 93 | 94 | fclose(f); 95 | __cfg_proc_line_pos = p - buf + 1; 96 | return CFG_PROC_SYNTAX; 97 | } 98 | 99 | char* key_name = p; 100 | while (*p && strchr(__allowed_chars, *p)) ++p; 101 | 102 | char* key_name_end = p; 103 | while (*p && strchr(__space_chars, *p)) ++p; 104 | 105 | if (*p != '=') 106 | { 107 | fclose(f); 108 | __cfg_proc_line_pos = p - buf + 1; 109 | return CFG_PROC_SYNTAX; 110 | } 111 | 112 | *key_name_end = 0; 113 | p++; 114 | while (*p && strchr(__space_chars, *p)) ++p; 115 | 116 | char* val = p; 117 | char* val_end = val; 118 | 119 | if (('"' == *p) || ('\'' == *p) || ('`' == *p)) 120 | { 121 | char open_quot_char = *p; 122 | 123 | p++; 124 | val++; 125 | 126 | while (*p && (*p != open_quot_char)) ++p; 127 | 128 | if (*p != open_quot_char) 129 | { 130 | fclose(f); 131 | __cfg_proc_line_pos = p - buf + 1; 132 | return CFG_PROC_SYNTAX; 133 | } 134 | 135 | val_end = p; 136 | p++; 137 | } 138 | else 139 | { 140 | while (*p && strchr(__allowed_chars_values, *p)) ++p; 141 | val_end = p; 142 | } 143 | 144 | while (*p && strchr(__space_chars, *p)) ++p; 145 | if (*p && (*p != ';') && (*p != '#')) 146 | { 147 | fclose(f); 148 | __cfg_proc_line_pos = p - buf + 1; 149 | return CFG_PROC_SYNTAX; 150 | } 151 | 152 | *val_end = 0; 153 | 154 | int r = _new_kv(key_name, val); 155 | if (r < 0) 156 | { 157 | fclose(f); 158 | __cfg_proc_line_pos = p - buf + 1; 159 | return r; 160 | } 161 | } 162 | 163 | fclose(f); 164 | 165 | return 0; 166 | } 167 | 168 | -------------------------------------------------------------------------------- /devices/BLK18E_0042/reverse/ipctool-reginfo.txt: -------------------------------------------------------------------------------- 1 | # ./ipctool-2024-03-26 reginfo 2 | muxctrl_reg0 0x200f0000 0x1 GPIO1_0 [SHUTTER_TRIG] 3 | muxctrl_reg1 0x200f0004 0x1 GPIO1_1 [SDIO_CCLK_OUT] 4 | muxctrl_reg2 0x200f0008 0x1 GPIO1_2 [SENSOR_CLK] 5 | muxctrl_reg3 0x200f000c 0 [GPIO1_4] SPI0_SCLK 6 | muxctrl_reg4 0x200f0010 0 [GPIO1_5] SPI0_SDO 7 | muxctrl_reg5 0x200f0014 0 [GPIO1_6] SPI0_SDI 8 | muxctrl_reg6 0x200f0018 0x1 GPIO2_0 [I2C_SDA] 9 | muxctrl_reg7 0x200f001c 0x1 GPIO2_1 [I2C_SCL] 10 | muxctrl_reg8 0x200f0020 0x1 GPIO2_2 [UART1_RTSN] 11 | muxctrl_reg9 0x200f0024 0 [GPIO2_3] UART1_RXD 12 | muxctrl_reg10 0x200f0028 0x1 GPIO2_4 [UART1_CTSN] 13 | muxctrl_reg11 0x200f002c 0 [GPIO2_5] UART1_TXD 14 | muxctrl_reg12 0x200f0030 0 [GPIO3_0] MII_CRS VOU1120_DATA10 15 | muxctrl_reg13 0x200f0034 0x1 GPIO3_1 [MII_COL] VOU1120_DATA9 16 | muxctrl_reg14 0x200f0038 0x1 GPIO4_3 [MII_RXD3] VOU1120_DATA15 17 | muxctrl_reg15 0x200f003c 0x1 GPIO4_2 [MII_RXD2] VOU1120_DATA11 18 | muxctrl_reg16 0x200f0040 0x1 GPIO4_1 [MII_RXD1] VOU1120_DATA8 19 | muxctrl_reg17 0x200f0044 0x1 GPIO4_0 [MII_RXD0] VOU1120_DATA12 20 | muxctrl_reg18 0x200f0048 0 [GPIO4_7] MII_TXD3 VOU1120_DATA3 21 | muxctrl_reg19 0x200f004c 0 [GPIO4_6] MII_TXD2 VOU1120_DATA13 22 | muxctrl_reg20 0x200f0050 0x1 GPIO4_5 [MII_TXD1] VOU1120_DATA0 23 | muxctrl_reg21 0x200f0054 0x1 GPIO4_4 [MII_TXD0] VOU1120_DATA4 24 | muxctrl_reg22 0x200f0058 0 [GPIO3_2] MII_RXCK VOU1120_CLK 25 | muxctrl_reg23 0x200f005c 0x3 GPIO3_3 MII_TXCK VOU1120_DATA7 [RMII_CLK] 26 | muxctrl_reg24 0x200f0060 0x1 GPIO3_4 [MII_RXDV] VOU1120_DATA1 27 | muxctrl_reg25 0x200f0064 0x1 GPIO3_5 [MII_TXEN] VOU1120_DATA5 28 | muxctrl_reg26 0x200f0068 0x1 GPIO2_6 [MII_TXER] 29 | muxctrl_reg27 0x200f006c 0x1 GPIO2_7 [MII_RXER] 30 | muxctrl_reg28 0x200f0070 0 [GPIO1_3] EPHY_CLK VOU1120_DATA2 31 | muxctrl_reg29 0x200f0074 0x1 GPIO3_6 [MDCK] VOU1120_DATA6 BOOT_SEL 32 | muxctrl_reg30 0x200f0078 0x1 GPIO3_7 [MDIO] VOU1120_DATA14 33 | muxctrl_reg31 0x200f007c 0x1 GPIO1_7 [FLASH_TRIG] 34 | muxctrl_reg32 0x200f0080 0 [GPIO6_0] SDIO_CARD_DETECT 35 | muxctrl_reg33 0x200f0084 0 [GPIO6_1] SDIO_CARD_POWER_EN 36 | muxctrl_reg34 0x200f0088 0x1 GPIO6_2 [SDIO_CWPR] 37 | muxctrl_reg35 0x200f008c 0x1 GPIO6_3 [SDIO_CCMD] 38 | muxctrl_reg36 0x200f0090 0x1 GPIO6_4 [SDIO_CDATA0] CLK_TEST_OUT0 CLK_TEST_OUT1 CLK_TEST_OUT2 CLK_TEST_OUT3 39 | muxctrl_reg37 0x200f0094 0x1 PLL_TEST_OUT0 [SDIO_CDATA1] GPIO6_5 PLL_TEST_OUT1 PLL_TEST_OUT2 PLL_TEST_OUT3 RTC_TEST_CLK 40 | muxctrl_reg38 0x200f0098 0x1 GPIO6_6 [SDIO_CDATA2] 41 | muxctrl_reg39 0x200f009c 0x1 GPIO6_7 [SDIO_CDATA3] 42 | muxctrl_reg40 0x200f00a0 0 [SFC_DIO] GPIO7_0 43 | muxctrl_reg41 0x200f00a4 0 [SFC_WP_IO2] GPIO7_1 44 | muxctrl_reg42 0x200f00a8 0 [SFC_CLK] GPIO7_2 SFC_ADDR_MODE 45 | muxctrl_reg43 0x200f00ac 0 [SFC_DOI] GPIO7_3 46 | muxctrl_reg44 0x200f00b0 0 [SFC_HOLD_IO3] GPIO7_4 47 | muxctrl_reg45 0x200f00b4 0x1 GPIO5_0 [USB_OVRCUR] 48 | muxctrl_reg46 0x200f00b8 0 [GPIO5_1] USB_PWREN 49 | muxctrl_reg47 0x200f00bc 0 [GPIO5_2] PWM_OUT0 50 | muxctrl_reg48 0x200f00c0 0 [GPIO5_3] PWM_OUT1 51 | muxctrl_reg49 0x200f00c4 0x1 IR_IN [GPIO7_5] 52 | muxctrl_reg50 0x200f00c8 0x1 reserved [GPIO9_0] 53 | muxctrl_reg51 0x200f00cc 0x1 reserved [GPIO9_1] 54 | muxctrl_reg52 0x200f00d0 0x1 reserved [GPIO9_2] 55 | muxctrl_reg53 0x200f00d4 0x1 reserved [GPIO9_3] 56 | muxctrl_reg54 0x200f00d8 0x1 reserved [GPIO9_4] 57 | muxctrl_reg55 0x200f00dc 0x1 reserved [GPIO9_5] 58 | muxctrl_reg56 0x200f00e0 0x1 reserved [GPIO9_6] 59 | muxctrl_reg57 0x200f00e4 0x1 reserved [GPIO9_7] 60 | muxctrl_reg58 0x200f0108 0 [GPIO7_6] UART2_RXD 61 | muxctrl_reg59 0x200f010c 0 [GPIO7_7] UART2_TXD 62 | muxctrl_reg60 0x200f0110 0 [GPIO5_4] SPI1_SCLK 63 | muxctrl_reg61 0x200f0114 0 [GPIO5_5] SPI1_SDO 64 | muxctrl_reg62 0x200f0118 0 [GPIO5_6] SPI1_SDI 65 | muxctrl_reg63 0x200f011c 0 [GPIO5_7] SPI1_CSN 66 | muxctrl_reg64 0x200f0120 0 [GPIO0_0] JTAG_TRSTN TEMPER_DQ 67 | muxctrl_reg65 0x200f0124 0 [GPIO0_1] JTAG_TCK TEMPER_DQ 68 | muxctrl_reg66 0x200f0128 0 [GPIO0_2] JTAG_TMS TEMPER_DQ 69 | muxctrl_reg67 0x200f012c 0 [GPIO0_3] JTAG_TDO TEMPER_DQ 70 | muxctrl_reg68 0x200f0130 0 [GPIO0_4] JTAG_TDI TEMPER_DQ 71 | muxctrl_reg69 0x200f0134 0x1 SVB_PWM [GPIO0_5] TEMPER_DQ 72 | muxctrl_reg70 0x200f0138 0x1 GPIO0_6 [SVB_PWM] TEMPER_DQ 73 | muxctrl_reg71 0x200f013c 0 [SYS_RSTN_OUT] GPIO0_7 TEMPER_DQ 74 | muxctrl_reg72 0x200f0140 0 [VIU_CLK] GPIO11_6 75 | muxctrl_reg73 0x200f0144 0 [VIU_VS] GPIO11_5 76 | muxctrl_reg74 0x200f0148 0 [VIU_HS] GPIO11_4 77 | muxctrl_reg75 0x200f014c 0 [VIU_DAT11] GPIO11_3 78 | muxctrl_reg76 0x200f0150 0 [VIU_DAT10] GPIO11_2 79 | muxctrl_reg77 0x200f0154 0 [VIU_DAT9] GPIO11_1 80 | muxctrl_reg78 0x200f0158 0 [VIU_DAT8] GPIO11_0 81 | muxctrl_reg79 0x200f015c 0 [VIU_DAT7] GPIO10_7 82 | muxctrl_reg80 0x200f0160 0 [VIU_DAT6] GPIO10_6 83 | muxctrl_reg81 0x200f0164 0 [VIU_DAT5] GPIO10_5 84 | muxctrl_reg82 0x200f0168 0 [VIU_DAT4] GPIO10_4 85 | muxctrl_reg83 0x200f016c 0 [VIU_DAT3] GPIO10_3 86 | muxctrl_reg84 0x200f0170 0 [VIU_DAT2] GPIO10_2 87 | muxctrl_reg85 0x200f0174 0 [VIU_DAT1] GPIO10_1 88 | muxctrl_reg86 0x200f0178 0 [VIU_DAT0] GPIO10_0 89 | 90 | -------------------------------------------------------------------------------- /cfg/sensor_config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "compat.h" 4 | #include "common.h" 5 | 6 | #if HISILICON_SDK_GEN >= 2 7 | struct SensorMIPI { 8 | raw_data_type_e data_type; 9 | int lane_id[8]; 10 | }; 11 | 12 | struct SensorLVDS { 13 | int img_size_w; 14 | int img_size_h; 15 | wdr_mode_t wdr_mode; 16 | lvds_sync_mode_t sync_mode; 17 | data_type_t raw_data_type; 18 | lvds_bit_endian_t data_endian; 19 | lvds_bit_endian_t sync_code_endian; 20 | int lane_id[8]; 21 | int lvds_lane_num; 22 | int wdr_vc_num; 23 | int sync_code_num; 24 | int sync_code[8][16]; 25 | }; 26 | #endif 27 | 28 | struct SensorVIDEV { 29 | VI_INPUT_MODE_E input_mod; 30 | VI_WORK_MODE_E work_mod; 31 | VI_COMBINE_MODE_E combine_mode; 32 | VI_COMP_MODE_E comp_mode; 33 | VI_CLK_EDGE_E clock_edge; 34 | unsigned int mask_num; 35 | unsigned int mask_0; 36 | unsigned int mask_1; 37 | VI_SCAN_MODE_E scan_mode; 38 | VI_DATA_YUV_SEQ_E data_seq; 39 | VI_VSYNC_E vsync; 40 | VI_VSYNC_NEG_E vsync_neg; 41 | VI_HSYNC_E hsync; 42 | VI_HSYNC_NEG_E hsync_neg; 43 | VI_VSYNC_VALID_E vsync_valid; 44 | VI_VSYNC_VALID_NEG_E vsync_valid_neg; 45 | unsigned int timing_blank_hsync_hfb; 46 | unsigned int timing_blank_hsync_act; 47 | unsigned int timing_blank_hsync_hbb; 48 | unsigned int timing_blank_vsync_vfb; 49 | unsigned int timing_blank_vsync_vact; 50 | unsigned int timing_blank_vsync_vbb; 51 | unsigned int timing_blank_vsync_vbfb; 52 | unsigned int timing_blank_vsync_vbact; 53 | unsigned int timing_blank_vsync_vbbb; 54 | 55 | BT656_FIXCODE_E fix_code; 56 | BT656_FIELD_POLAR_E field_polar; 57 | VI_DATA_PATH_E data_path; 58 | VI_DATA_TYPE_E input_data_type; 59 | int data_rev; 60 | int dev_rect_x; 61 | int dev_rect_y; 62 | unsigned int dev_rect_w; 63 | unsigned int dev_rect_h; 64 | }; 65 | 66 | extern const char *cfg_sensor_vals_bool[]; 67 | extern const char *cfg_sensor_vals_videv_input_mod[]; 68 | extern const char *cfg_sensor_vals_videv_work_mod[]; 69 | extern const char *cfg_sensor_vals_videv_combine_mode[]; 70 | extern const char *cfg_sensor_vals_videv_comp_mode[]; 71 | extern const char *cfg_sensor_vals_videv_clock_edge[]; 72 | extern const char *cfg_sensor_vals_videv_scan_mode[]; 73 | extern const char *cfg_sensor_vals_videv_data_seq[]; 74 | extern const char *cfg_sensor_vals_videv_vsync[]; 75 | extern const char *cfg_sensor_vals_videv_vsync_neg[]; 76 | extern const char *cfg_sensor_vals_videv_hsync[]; 77 | extern const char *cfg_sensor_vals_videv_hsync_neg[]; 78 | extern const char *cfg_sensor_vals_videv_vsync_valid[]; 79 | extern const char *cfg_sensor_vals_videv_vsync_valid_neg[]; 80 | extern const char *cfg_sensor_vals_videv_fix_code[]; 81 | extern const char *cfg_sensor_vals_videv_field_polar[]; 82 | extern const char *cfg_sensor_vals_videv_data_path[]; 83 | extern const char *cfg_sensor_vals_videv_input_data_type[]; 84 | 85 | struct SensorISP { 86 | int isp_x; 87 | int isp_y; 88 | unsigned int isp_h; 89 | unsigned int isp_w; 90 | unsigned int isp_frame_rate; 91 | ISP_BAYER_FORMAT_E isp_bayer; 92 | }; 93 | 94 | extern const char *cfg_sensor_vals_isp_bayer[]; 95 | 96 | struct SensorVIChn { 97 | int cap_rect_x; 98 | int cap_rect_y; 99 | unsigned int cap_rect_width; 100 | unsigned int cap_rect_height; 101 | unsigned int dest_size_width; 102 | unsigned int dest_size_height; 103 | VI_CAPSEL_E cap_sel; 104 | PIXEL_FORMAT_E pix_format; 105 | #if HISILICON_SDK_GEN >= 2 106 | COMPRESS_MODE_E compress_mode; 107 | #endif 108 | int src_frame_rate; 109 | int frame_rate; 110 | }; 111 | 112 | struct SensorVIExt { 113 | unsigned int width; 114 | unsigned int height; 115 | PIXEL_FORMAT_E pix_format; 116 | 117 | int src_frame_rate; 118 | int frame_rate; 119 | }; 120 | 121 | extern const char *cfg_sensor_vals_vichn_capsel[]; 122 | extern const char *cfg_sensor_vals_vichn_pixel_format[]; 123 | 124 | struct SensorConfig { 125 | // VB 126 | unsigned vb_cnt; 127 | 128 | // [sensor] 129 | char sensor_type[128]; 130 | #if HISILICON_SDK_GEN >= 2 131 | WDR_MODE_E mode; 132 | #endif 133 | char dll_file[256]; 134 | 135 | #if HISILICON_SDK_GEN >= 2 136 | // [mode] 137 | input_mode_t input_mode; 138 | 139 | // [mipi] 140 | struct SensorMIPI mipi; 141 | 142 | // [lvds] 143 | struct SensorLVDS lvds; 144 | #endif 145 | 146 | // [isp_image] 147 | struct SensorISP isp; 148 | 149 | // [vi_dev] 150 | struct SensorVIDEV videv; 151 | 152 | // [vi_chn] 153 | struct SensorVIChn vichn; 154 | 155 | // [vi_ext] 156 | struct SensorVIExt viext; 157 | }; 158 | 159 | int cfg_sensor_read(const char* fname, struct SensorConfig* sc); 160 | const char* cfg_sensor_read_error_key(); 161 | const char* cfg_sensor_read_error_value(); 162 | 163 | void cfg_sensor_pretty_print(const struct SensorConfig* sc); 164 | 165 | 166 | -------------------------------------------------------------------------------- /imx225_spi/imx225_sensor_ctl.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | 3 | Copyright (C), 2001-2011, Hisilicon Tech. Co., Ltd. 4 | 5 | ****************************************************************************** 6 | File Name : sony225_sensor_ctl.c 7 | Version : Initial Draft 8 | Author : Hisilicon multimedia software group 9 | Created : 2014/11/07 10 | Description : Sony IMX225 sensor driver 11 | History : 12 | 1.Date : 2014/11/07 13 | Author : MPP 14 | Modification: Created file 15 | 16 | ******************************************************************************/ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "hi_ssp.h" 25 | 26 | int sony_sensor_write_packet(unsigned int data) 27 | { 28 | int fd = -1; 29 | int ret; 30 | unsigned int value; 31 | 32 | fd = open("/dev/ssp", 0); 33 | if(fd < 0) 34 | { 35 | printf("Open /dev/ssp error!\n"); 36 | return -1; 37 | } 38 | 39 | value = data; 40 | 41 | ret = ioctl(fd, SSP_WRITE_ALT, &value); 42 | 43 | close(fd); 44 | return 0; 45 | } 46 | 47 | int sony_sensor_read_packet(unsigned int data) 48 | { 49 | unsigned int value; 50 | int fd = -1; 51 | int ret; 52 | 53 | fd = open("/dev/ssp", 0); 54 | if(fd < 0) 55 | { 56 | printf("Open /dev/ssp error!\n"); 57 | return -1; 58 | } 59 | 60 | value = data; 61 | 62 | ret = ioctl(fd, SSP_READ_ALT, &value); 63 | 64 | close(fd); 65 | return (value&0xff); 66 | } 67 | 68 | int sensor_write_register(int addr, int data) 69 | { 70 | unsigned int value = (unsigned int)(((addr&0xffff)<<8) | (data & 0xff)); 71 | return sony_sensor_write_packet(value); 72 | } 73 | 74 | int sensor_read_register(int addr) 75 | { 76 | unsigned int data = (unsigned int)(((addr&0xffff)<<8)); 77 | return sony_sensor_read_packet(data); 78 | } 79 | 80 | void sensor_prog(int* rom) 81 | { 82 | } 83 | 84 | 85 | void sensor_init() 86 | { 87 | 88 | sensor_write_register(0x200, 0x01); //Standby 89 | usleep(200000); 90 | 91 | 92 | // chip_id = 0x2 93 | sensor_write_register(0x207, 0x00); // was 0x10 94 | sensor_write_register(0x209, 0x11); // was 0x01 95 | sensor_write_register(0x20f, 0x00); 96 | sensor_write_register(0x212, 0x2c); 97 | sensor_write_register(0x213, 0x01); 98 | sensor_write_register(0x216, 0x09); 99 | sensor_write_register(0x218, 0x40); // was 0xee 100 | sensor_write_register(0x219, 0x0a); // was 0x0a 101 | sensor_write_register(0x21b, 0xa0); // was 0xc8 102 | sensor_write_register(0x21c, 0x11); // was 0x19 103 | sensor_write_register(0x21d, 0xc2); 104 | sensor_write_register(0x246, 0x00); // was 0x03 105 | sensor_write_register(0x247, 0x08); // was 0x06 106 | sensor_write_register(0x248, 0x00); // was 0xc2 107 | sensor_write_register(0x249, 0x0a); // was ---- 108 | sensor_write_register(0x232, 0x4c); // was ---- 109 | sensor_write_register(0x25c, 0x2c); 110 | sensor_write_register(0x25D, 0x00); 111 | sensor_write_register(0x25E, 0x2c); 112 | sensor_write_register(0x25F, 0x00); 113 | sensor_write_register(0x270, 0x02); 114 | sensor_write_register(0x271, 0x01); 115 | sensor_write_register(0x29E, 0x22); 116 | sensor_write_register(0x2A5, 0xFB); 117 | sensor_write_register(0x2A6, 0x02); 118 | sensor_write_register(0x2B3, 0xFF); 119 | sensor_write_register(0x2B4, 0x01); 120 | sensor_write_register(0x2B5, 0x42); 121 | sensor_write_register(0x2B8, 0x10); 122 | sensor_write_register(0x2C2, 0x01); 123 | 124 | // chip_id = 0x3 125 | sensor_write_register(0x30F, 0x0F); 126 | sensor_write_register(0x310, 0x0E); 127 | sensor_write_register(0x311, 0xE7); 128 | sensor_write_register(0x312, 0x9C); 129 | sensor_write_register(0x313, 0x83); 130 | sensor_write_register(0x314, 0x10); 131 | sensor_write_register(0x315, 0x42); 132 | sensor_write_register(0x328, 0x1E); 133 | sensor_write_register(0x3ED, 0x38); 134 | sensor_write_register(0x3df, 0x53); 135 | 136 | // chip_id = 0x4 137 | sensor_write_register(0x40C, 0xCF); 138 | sensor_write_register(0x44C, 0x40); 139 | sensor_write_register(0x44D, 0x03); 140 | sensor_write_register(0x461, 0xE0); 141 | sensor_write_register(0x462, 0x02); 142 | sensor_write_register(0x46E, 0x2F); 143 | sensor_write_register(0x46F, 0x30); 144 | sensor_write_register(0x470, 0x03); 145 | sensor_write_register(0x498, 0x00); 146 | sensor_write_register(0x49A, 0x12); 147 | sensor_write_register(0x49B, 0xF1); 148 | sensor_write_register(0x49C, 0x0C); 149 | 150 | usleep(200000); 151 | sensor_write_register(0x200, 0x00); //release standy 152 | usleep(200000); 153 | sensor_write_register(0x202, 0x00); //Master mose start 154 | usleep(200000); 155 | sensor_write_register(0x249, 0x80); //XVS & XHS output 156 | usleep(200000); 157 | 158 | printf("-------Sony IMX225 Sensor Initial OK!-------\n"); 159 | 160 | return ; 161 | 162 | } 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /imx225_i2c_960h/imx225_sensor_ctl.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | 3 | Copyright (C), 2001-2011, Hisilicon Tech. Co., Ltd. 4 | 5 | ****************************************************************************** 6 | File Name : sony225_sensor_ctl.c 7 | Version : Initial Draft 8 | Author : Hisilicon multimedia software group 9 | Created : 2014/11/07 10 | Description : Sony IMX225 sensor driver 11 | History : 12 | 1.Date : 2014/11/07 13 | Author : MPP 14 | Modification: Created file 15 | 16 | ******************************************************************************/ 17 | #include 18 | // #include 19 | // #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "hi_i2c.h" 25 | 26 | int sony_sensor_write_packet(I2C_DATA_S i2c_data) 27 | { 28 | int fd = -1; 29 | int ret; 30 | 31 | fd = open("/dev/hi_i2c", 0); 32 | if(fd < 0) 33 | { 34 | printf("Open /dev/hi_i2c error!\n"); 35 | return -1; 36 | } 37 | 38 | ret = ioctl(fd, CMD_I2C_WRITE, &i2c_data); 39 | 40 | close(fd); 41 | return 0; 42 | } 43 | 44 | 45 | int sensor_write_register(int reg_addr, int reg_value) 46 | { 47 | I2C_DATA_S i2c_data ; 48 | unsigned int reg_width = 2; 49 | unsigned int data_width = 1; 50 | unsigned int device_addr = 0x34; 51 | 52 | i2c_data.dev_addr = device_addr ; 53 | i2c_data.reg_addr = reg_addr ; 54 | i2c_data.addr_byte_num = reg_width ; 55 | i2c_data.data = reg_value ; 56 | i2c_data.data_byte_num = data_width ; 57 | 58 | return sony_sensor_write_packet(i2c_data); 59 | } 60 | 61 | void sensor_prog(int* rom) 62 | { 63 | } 64 | 65 | 66 | void sensor_init() 67 | { 68 | 69 | sensor_write_register(0x3000, 0x01); //Standby 70 | usleep(200000); 71 | 72 | // chip_id = 0x2 73 | sensor_write_register(0x3007, 0x00); //Window mode: 1280x960 mode 74 | sensor_write_register(0x3009, 0x11); //(0x01) 30fps mode + (0x10) HCG Mode 75 | sensor_write_register(0x300f, 0x00); // magic 76 | sensor_write_register(0x3012, 0x2c); // magic 77 | sensor_write_register(0x3013, 0x01); // magic 78 | sensor_write_register(0x3016, 0x09); // magic? 79 | 80 | sensor_write_register(0x3018, 0x4C); // VMAX = 0x0528 for 25/50 frame/s 81 | sensor_write_register(0x3019, 0x04); 82 | 83 | sensor_write_register(0x301b, 0x90); // HMAX = 0x1194 84 | sensor_write_register(0x301c, 0x11); 85 | 86 | sensor_write_register(0x301d, 0xc2); // magic number 87 | sensor_write_register(0x3032, 0x4b); // magic number, from stock 88 | 89 | sensor_write_register(0x3044, 0x01); // (0x01) ODBIT 12bit + (0x00) OPORTSEL == CMOS 90 | sensor_write_register(0x3046, 0x03); // XVSLNG 91 | sensor_write_register(0x3047, 0x06); // XHSLNG 92 | sensor_write_register(0x3048, 0xc2); // ?? 93 | 94 | sensor_write_register(0x3054, 0x67); // CMOS == 0x67 95 | 96 | sensor_write_register(0x305C, 0x20); // INCKSEL1 (INCK 37.125 MHz) 97 | sensor_write_register(0x305D, 0x00); // INCKSEL2 98 | sensor_write_register(0x305E, 0x20); // INCKSEL3 99 | sensor_write_register(0x305F, 0x00); // INCKSEL4 100 | 101 | sensor_write_register(0x3070, 0x02); 102 | sensor_write_register(0x3071, 0x01); 103 | sensor_write_register(0x309E, 0x22); 104 | sensor_write_register(0x30A5, 0xFB); 105 | sensor_write_register(0x30A6, 0x02); 106 | sensor_write_register(0x30B3, 0xFF); 107 | sensor_write_register(0x30B4, 0x01); 108 | sensor_write_register(0x30B5, 0x42); 109 | sensor_write_register(0x30B8, 0x10); 110 | sensor_write_register(0x30C2, 0x01); 111 | 112 | // chip_id = 0x3 113 | sensor_write_register(0x310F, 0x0F); 114 | sensor_write_register(0x3110, 0x0E); 115 | sensor_write_register(0x3111, 0xE7); 116 | sensor_write_register(0x3112, 0x9C); 117 | sensor_write_register(0x3113, 0x83); 118 | sensor_write_register(0x3114, 0x10); 119 | sensor_write_register(0x3115, 0x42); 120 | sensor_write_register(0x3128, 0x1E); 121 | sensor_write_register(0x31ED, 0x38); 122 | 123 | // chip_id = 0x4 124 | sensor_write_register(0x320C, 0xCF); 125 | sensor_write_register(0x324C, 0x40); 126 | sensor_write_register(0x324D, 0x03); 127 | sensor_write_register(0x3261, 0xE0); 128 | sensor_write_register(0x3262, 0x02); 129 | sensor_write_register(0x326E, 0x2F); 130 | sensor_write_register(0x326F, 0x30); 131 | sensor_write_register(0x3270, 0x03); 132 | sensor_write_register(0x3298, 0x00); 133 | sensor_write_register(0x329A, 0x12); 134 | sensor_write_register(0x329B, 0xF1); 135 | sensor_write_register(0x329C, 0x0C); 136 | 137 | usleep(200000); 138 | sensor_write_register(0x3000, 0x00); //release standy 139 | usleep(200000); 140 | sensor_write_register(0x3002, 0x00); //Master mode start 141 | usleep(200000); 142 | sensor_write_register(0x3049, 0x80); //XVS & XHS output 143 | usleep(200000); 144 | 145 | printf("-------Sony IMX225 Sensor Initial OK!-------\n"); 146 | 147 | return ; 148 | 149 | } 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /libev/ev_poll.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libev poll fd activity backend 3 | * 4 | * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modifica- 8 | * tion, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26 | * OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * Alternatively, the contents of this file may be used under the terms of 29 | * the GNU General Public License ("GPL") version 2 or any later version, 30 | * in which case the provisions of the GPL are applicable instead of 31 | * the above. If you wish to allow the use of your version of this file 32 | * only under the terms of the GPL and not to allow others to use your 33 | * version of this file under the BSD license, indicate your decision 34 | * by deleting the provisions above and replace them with the notice 35 | * and other provisions required by the GPL. If you do not delete the 36 | * provisions above, a recipient may use your version of this file under 37 | * either the BSD or the GPL. 38 | */ 39 | 40 | #include 41 | 42 | void inline_size 43 | pollidx_init (int *base, int count) 44 | { 45 | /* consider using memset (.., -1, ...), which is practically guaranteed 46 | * to work on all systems implementing poll */ 47 | while (count--) 48 | *base++ = -1; 49 | } 50 | 51 | static void 52 | poll_modify (EV_P_ int fd, int oev, int nev) 53 | { 54 | int idx; 55 | 56 | if (oev == nev) 57 | return; 58 | 59 | array_needsize (int, pollidxs, pollidxmax, fd + 1, pollidx_init); 60 | 61 | idx = pollidxs [fd]; 62 | 63 | if (idx < 0) /* need to allocate a new pollfd */ 64 | { 65 | pollidxs [fd] = idx = pollcnt++; 66 | array_needsize (struct pollfd, polls, pollmax, pollcnt, EMPTY2); 67 | polls [idx].fd = fd; 68 | } 69 | 70 | assert (polls [idx].fd == fd); 71 | 72 | if (nev) 73 | polls [idx].events = 74 | (nev & EV_READ ? POLLIN : 0) 75 | | (nev & EV_PRI ? POLLPRI : 0) 76 | | (nev & EV_WRITE ? POLLOUT : 0); 77 | else /* remove pollfd */ 78 | { 79 | pollidxs [fd] = -1; 80 | 81 | if (expect_true (idx < --pollcnt)) 82 | { 83 | polls [idx] = polls [pollcnt]; 84 | pollidxs [polls [idx].fd] = idx; 85 | } 86 | } 87 | } 88 | 89 | static void 90 | poll_poll (EV_P_ ev_tstamp timeout) 91 | { 92 | struct pollfd *p; 93 | int res; 94 | 95 | EV_RELEASE_CB; 96 | res = poll (polls, pollcnt, timeout * 1e3); 97 | EV_ACQUIRE_CB; 98 | 99 | if (expect_false (res < 0)) 100 | { 101 | if (errno == EBADF) 102 | fd_ebadf (EV_A); 103 | else if (errno == ENOMEM && !syserr_cb) 104 | fd_enomem (EV_A); 105 | else if (errno != EINTR) 106 | ev_syserr ("(libev) poll"); 107 | } 108 | else 109 | for (p = polls; res; ++p) 110 | { 111 | assert (("libev: poll() returned illegal result, broken BSD kernel?", p < polls + pollcnt)); 112 | 113 | if (expect_false (p->revents)) /* this expect is debatable */ 114 | { 115 | --res; 116 | 117 | if (expect_false (p->revents & POLLNVAL)) 118 | fd_kill (EV_A_ p->fd); 119 | else 120 | fd_event ( 121 | EV_A_ 122 | p->fd, 123 | (p->revents & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0) 124 | | (p->revents & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0) 125 | | (p->revents & (POLLPRI | POLLERR | POLLHUP) ? EV_PRI : 0) 126 | ); 127 | } 128 | } 129 | } 130 | 131 | int inline_size 132 | poll_init (EV_P_ int flags) 133 | { 134 | backend_mintime = 1e-3; 135 | backend_modify = poll_modify; 136 | backend_poll = poll_poll; 137 | 138 | pollidxs = 0; pollidxmax = 0; 139 | polls = 0; pollmax = 0; pollcnt = 0; 140 | 141 | return EVBACKEND_POLL; 142 | } 143 | 144 | void inline_size 145 | poll_destroy (EV_P) 146 | { 147 | ev_free (pollidxs); 148 | ev_free (polls); 149 | } 150 | 151 | -------------------------------------------------------------------------------- /platform/sdk_audio_tiny.c: -------------------------------------------------------------------------------- 1 | #include "sdk.h" 2 | 3 | #include 4 | 5 | #include "hi_common.h" 6 | #include "hi_comm_sys.h" 7 | #include "hi_comm_vb.h" 8 | #include "mpi_sys.h" 9 | #include "mpi_vb.h" 10 | #include "hi_comm_ao.h" 11 | #include "hi_comm_aio.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "acodec.h" 23 | 24 | const char* __sdk_last_call = 0; 25 | 26 | 27 | #define AUDIO_PTNUMPERFRM 320 28 | 29 | #define ACODEC_FILE "/dev/acodec" 30 | #define AUDIO_ADPCM_TYPE ADPCM_TYPE_DVI4/* ADPCM_TYPE_IMA, ADPCM_TYPE_DVI4*/ 31 | #define G726_BPS MEDIA_G726_40K /* MEDIA_G726_16K, MEDIA_G726_24K ... */ 32 | 33 | int init_sdk_audio_CfgAcodec(AUDIO_SAMPLE_RATE_E enSample, HI_BOOL bMicIn) 34 | { 35 | HI_S32 fdAcodec = -1; 36 | 37 | __sdk_last_call = "open(" ACODEC_FILE ")"; 38 | fdAcodec = open(ACODEC_FILE,O_RDWR); 39 | if (fdAcodec < 0) return -1; 40 | 41 | HI_S32 s32Ret = 0; 42 | s32Ret = ioctl(fdAcodec, ACODEC_SOFT_RESET_CTRL); 43 | if (0 != s32Ret) 44 | { 45 | __sdk_last_call = "acodec ACODEC_SOFT_RESET_CTRL"; 46 | close(fdAcodec); 47 | return s32Ret; 48 | } 49 | 50 | unsigned int i2s_fs_sel = 0; 51 | switch (enSample) 52 | { 53 | case AUDIO_SAMPLE_RATE_8000: 54 | case AUDIO_SAMPLE_RATE_11025: 55 | case AUDIO_SAMPLE_RATE_12000: 56 | i2s_fs_sel = 0x18; 57 | break; 58 | 59 | case AUDIO_SAMPLE_RATE_16000: 60 | case AUDIO_SAMPLE_RATE_22050: 61 | case AUDIO_SAMPLE_RATE_24000: 62 | i2s_fs_sel = 0x19; 63 | break; 64 | 65 | case AUDIO_SAMPLE_RATE_32000: 66 | case AUDIO_SAMPLE_RATE_44100: 67 | case AUDIO_SAMPLE_RATE_48000: 68 | i2s_fs_sel = 0x1a; 69 | break; 70 | 71 | default: 72 | __sdk_last_call = "AUDIO_SAMPLE_RATE"; 73 | close(fdAcodec); 74 | return -1; 75 | } 76 | 77 | 78 | if (ioctl(fdAcodec, ACODEC_SET_I2S1_FS, &i2s_fs_sel)) 79 | { 80 | __sdk_last_call = "acodec ACODEC_SET_I2S1_FS"; 81 | s32Ret = -1; 82 | } 83 | 84 | close(fdAcodec); 85 | return s32Ret; 86 | } 87 | 88 | int hitiny_MPI_AO_GetFd(AUDIO_DEV AoDevId, AO_CHN AoChn) 89 | { 90 | int fd = open("/dev/ao", 2); 91 | 92 | if (fd < 0) return fd; 93 | 94 | unsigned param = AoDevId * 2 + AoChn; 95 | 96 | int ret = ioctl(fd, 0x40045800, ¶m); 97 | if (ret) 98 | { 99 | close(fd); 100 | return ret; 101 | } 102 | 103 | return fd; 104 | } 105 | 106 | int hitiny_MPI_AO_SetPubAttr(int fd, AIO_ATTR_S *pstAioAttr) 107 | { 108 | return ioctl(fd, 0x40245801, pstAioAttr); 109 | } 110 | 111 | int hitiny_MPI_AO_EnableDev(int fd) 112 | { 113 | return ioctl(fd, 0x5803); 114 | } 115 | 116 | int xhitiny_MPI_AO_EnableChn(int fd) 117 | { 118 | return ioctl(fd, 0x5808); 119 | } 120 | 121 | int hitiny_MPI_AO_DisableDev(int fd) 122 | { 123 | return ioctl(fd, 0x5804); 124 | } 125 | 126 | int hitiny_MPI_AO_DisableChn(int fd) 127 | { 128 | return ioctl(fd, 0x5809); 129 | } 130 | 131 | int fd_AO = -1; 132 | 133 | int init_sdk_audio_StartAo(AUDIO_DEV AoDevId, AO_CHN AoChn, AIO_ATTR_S *pstAioAttr, AUDIO_RESAMPLE_ATTR_S *pstAoReSmpAttr) 134 | { 135 | HI_S32 s32Ret; 136 | 137 | __sdk_last_call = "hitiny_MPI_AO_GetFd"; 138 | int fd = hitiny_MPI_AO_GetFd(0, 0); 139 | if (fd < 0) return fd; 140 | 141 | fprintf(stderr, "AO fd=%d (chn 0)\n", fd); 142 | 143 | __sdk_last_call = "HI_MPI_AO_SetPubAttr"; 144 | s32Ret = hitiny_MPI_AO_SetPubAttr(fd, pstAioAttr); 145 | if (HI_SUCCESS != s32Ret) return s32Ret; 146 | 147 | __sdk_last_call = "HI_MPI_AO_Enable"; 148 | s32Ret = hitiny_MPI_AO_EnableDev(fd); 149 | if (HI_SUCCESS != s32Ret) return s32Ret; 150 | 151 | s32Ret = hitiny_MPI_AO_EnableChn(fd); 152 | 153 | fd_AO = fd; 154 | 155 | return s32Ret; 156 | } 157 | 158 | 159 | int sdk_audio_init(int bMic, PAYLOAD_TYPE_E payload_type, int audio_rate) 160 | { 161 | AUDIO_DEV AoDev = 0; 162 | AO_CHN AoChn = 0; 163 | 164 | AIO_ATTR_S stAioAttr; 165 | memset(&stAioAttr, 0, sizeof(AIO_ATTR_S)); 166 | 167 | stAioAttr.enSamplerate = audio_rate; 168 | stAioAttr.enBitwidth = AUDIO_BIT_WIDTH_16; 169 | stAioAttr.enWorkmode = AIO_MODE_I2S_MASTER; 170 | stAioAttr.enSoundmode = AUDIO_SOUND_MODE_MONO; 171 | stAioAttr.u32EXFlag = 1; 172 | stAioAttr.u32FrmNum = 30; 173 | stAioAttr.u32PtNumPerFrm = AUDIO_PTNUMPERFRM; 174 | stAioAttr.u32ChnCnt = 2; 175 | stAioAttr.u32ClkSel = 1; 176 | 177 | __sdk_last_call = "init_sdk_audio_StartAo"; 178 | HI_S32 s32Ret = init_sdk_audio_StartAo(AoDev, AoChn, &stAioAttr, 0); 179 | if (HI_SUCCESS != s32Ret) return s32Ret; 180 | 181 | return 0; 182 | } 183 | 184 | void sdk_audio_done() 185 | { 186 | if (fd_AO > 0) 187 | { 188 | hitiny_MPI_AO_DisableChn(fd_AO); 189 | hitiny_MPI_AO_DisableDev(fd_AO); 190 | close(fd_AO); 191 | fd_AO = -1; 192 | } 193 | 194 | } 195 | 196 | int xhitiny_MPI_AO_SendFrame(int fd, AUDIO_FRAME_S* frame, int blocking_mode) 197 | { 198 | if (!blocking_mode) 199 | { 200 | struct pollfd x; 201 | x.fd = fd; 202 | x.events = POLLOUT; 203 | poll(&x, 1, 0); 204 | if (x.events != POLLOUT) return 0xA016800F; 205 | } 206 | 207 | int result = ioctl(fd, 0x40305805, frame); 208 | 209 | return result; 210 | } 211 | 212 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | project(hisinad C) 3 | 4 | set(CMAKE_C_STANDARD 99) 5 | 6 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") 7 | 8 | find_package(HiSiliconSDK REQUIRED) 9 | find_package(Threads REQUIRED) 10 | find_library(CURL_LIBRARY NAMES curl) 11 | 12 | include_directories(${CMAKE_SOURCE_DIR}) 13 | include_directories(${VENDOR_SDK_INCLUDE_DIRS}) 14 | include_directories(libev) 15 | 16 | if (HISILICON_SDK_VERSION STREQUAL "1.0.B.0.") 17 | add_definitions(-DISP_EX_ATTR) 18 | endif() 19 | 20 | add_library(hisinad_aux STATIC aux/logger.c aux/system.c) 21 | add_library(hisinad_cfg STATIC cfg/common.c cfg/sensor_config.c cfg/sensor_cfg_print.c) 22 | add_library(libevx STATIC libev/ev.c) 23 | add_library(evcurl STATIC evcurl/evcurl.c) 24 | 25 | add_executable(test_cfg_read test/test_cfg_read.c cfg/common.c) 26 | add_executable(test_cfg_sensor test/test_cfg_sensor.c) 27 | target_link_libraries(test_cfg_sensor hisinad_cfg) 28 | 29 | add_executable(test_tinydraw_0 test/test_tinydraw_0.c tinydraw/image.c tinydraw/save_bmp.c) 30 | add_executable(test_tinydraw_1 test/test_tinydraw_1.c tinydraw/image.c tinydraw/save_bmp.c tinydraw/monaco32_fixedsize_rawbb_2bpp.c tinydraw/font.c) 31 | add_executable(test_tinydraw_2 test/test_tinydraw_2.c tinydraw/image.c tinydraw/save_bmp.c tinydraw/monaco32_fixedsize_rawbb_2bpp.c tinydraw/font.c) 32 | 33 | add_executable(test_pumap_vi test/test_pumap_vi.c pumap/vi.c) 34 | 35 | if (CMAKE_SYSTEM_PROCESSOR STREQUAL armv5l) 36 | message(STATUS "Architecture: ${CMAKE_SYSTEM_PROCESSOR}") 37 | 38 | add_executable(test_ao test/test_ao.c platform/sdk_sys.c platform/sdk_audio.c platform/sdk_ugly.c) 39 | target_link_libraries(test_ao ${VENDOR_SDK_LIBRARIES} gcc_s hisicompat hisinad_aux hisinad_cfg) 40 | 41 | add_executable(test_ao_tiny hitiny/hitiny_sys.c hitiny/hitiny_aio.c hitiny/hitiny_ao.c test/test_ao_tiny.c) 42 | target_link_libraries(test_ao_tiny gcc_s hisinad_aux hisinad_cfg) 43 | 44 | add_executable(hisinad hisinad/daemon.c cfg/common.c platform/sdk_sys.c platform/sdk_ugly.c platform/sdk_sensor.c platform/sdk_isp.c) 45 | target_link_libraries(hisinad ${VENDOR_SDK_LIBRARIES} gcc_s hisicompat hisinad_aux hisinad_cfg) 46 | 47 | add_executable(test_jpeg test/test_jpeg.c cfg/common.c platform/sdk_sys.c platform/sdk_audio.c platform/sdk_ugly.c platform/sdk_sensor.c platform/sdk_isp.c) 48 | target_link_libraries(test_jpeg ${VENDOR_SDK_LIBRARIES} gcc_s hisicompat hisinad_aux hisinad_cfg) 49 | 50 | add_executable(test_md test/test_md.c cfg/common.c hitiny/hitiny_sys.c hitiny/hitiny_vda.c) 51 | target_link_libraries(test_md hisinad_aux) 52 | 53 | add_executable(test_vi_ext test/test_vi_ext.c hitiny/hitiny_vi.c cfg/common.c) 54 | target_link_libraries(test_vi_ext hisinad_aux hisinad_cfg) 55 | 56 | add_executable(test_jpeg_dn test/test_jpeg_dn.c cfg/common.c platform/sdk_sys.c platform/sdk_audio.c platform/sdk_ugly.c platform/sdk_sensor.c platform/sdk_isp.c) 57 | target_link_libraries(test_jpeg_dn ${VENDOR_SDK_LIBRARIES} gcc_s hisicompat hisinad_aux hisinad_cfg) 58 | 59 | add_executable(test_jpeg_nosdk test/test_jpeg_nosdk.c hitiny/hitiny_venc_fd.c hitiny/hitiny_sys.c) 60 | target_link_libraries(test_jpeg_nosdk hisinad_aux) 61 | 62 | add_executable(test_jpeg_rgn_nosdk test/test_jpeg_rgn_nosdk.c hitiny/hitiny_venc_fd.c hitiny/hitiny_sys.c hitiny/hitiny_region.c tinydraw/image.c tinydraw/save_bmp.c tinydraw/monaco32_fixedsize_rawbb_2bpp.c tinydraw/font.c) 63 | target_link_libraries(test_jpeg_rgn_nosdk hisinad_aux) 64 | 65 | add_executable(test_mmz_nosdk test/test_mmz.c hitiny/hitiny_sys.c) 66 | target_link_libraries(test_mmz_nosdk hisinad_aux) 67 | 68 | #add_executable(test_mmz_sdk test/test_mmz_sdk.c) 69 | #target_link_libraries(test_mmz_sdk ${VENDOR_SDK_LIBRARIES} gcc_s hisicompat hisinad_aux) 70 | 71 | add_executable(tools_vi_dump tools/vi_dump.c) 72 | target_link_libraries(tools_vi_dump ${VENDOR_SDK_LIBRARIES} gcc_s hisicompat) 73 | 74 | add_executable(tools_vi_dump_nosdk tools/vi_dump_nosdk.c hitiny/hitiny_vi.c hitiny/hitiny_sys.c hitiny/hitiny_ive.c) 75 | target_link_libraries(tools_vi_dump_nosdk hisinad_aux) 76 | 77 | add_executable(hisina-md-tune tools/hisina-md-tune/mjpeg_snap.c tools/hisina-md-tune/main.c hitiny/hitiny_sys.c hitiny/hitiny_vda.c cfg/vdacfg.c cfg/common.c hitiny/hitiny_venc_fd.c) 78 | target_link_libraries(hisina-md-tune evcurl hisinad_aux ${CURL_LIBRARY} libevx) 79 | 80 | add_executable(histodiffer tools/histodiffer.c hitiny/hitiny_vi.c hitiny/hitiny_sys.c hitiny/hitiny_ive.c) 81 | target_link_libraries(histodiffer hisinad_aux) 82 | 83 | add_executable(tools_vi_ive_hist tools/vi_ive_hist.c) 84 | target_link_libraries(tools_vi_ive_hist ${VENDOR_SDK_LIBRARIES} gcc_s hisicompat) 85 | 86 | add_executable(tools_hi_vi_reg tools/hi_vireg.c platform/sdk_ugly.c) 87 | 88 | add_executable(tool_pwm1 tools/pwm1_manager.c) 89 | 90 | add_library(sns_imx225_i2c_720p SHARED imx225_i2c/imx225_cmos.c imx225_i2c/imx225_sensor_ctl.c) 91 | add_library(sns_imx225_i2c_960p SHARED imx225_i2c_960h/imx225_cmos.c imx225_i2c_960h/imx225_sensor_ctl.c) 92 | add_library(sns_imx225_spi_720p SHARED imx225_spi/imx225_cmos.c imx225_spi/imx225_sensor_ctl.c) 93 | add_library(sns_jxh42_i2c SHARED jxh42_i2c/jxh42_sensor_ctl.c jxh42_i2c/jxh42_cmos.c) 94 | add_library(sns_jxh22_i2c SHARED jxh22_i2c/jxh22_sensor_ctl.c jxh22_i2c/jxh22_cmos.c) 95 | #add_library(sns_sc2135_i2c SHARED sc2135/sc2135_sensor_ctl.c sc2135/sc2135_cmos.c) 96 | 97 | add_executable(sample_audio test/sample_audio/sample_audio.c test/sample_audio/sample_comm_audio.c test/sample_audio/sample_comm_sys.c platform/sdk_ugly.c) 98 | target_link_libraries(sample_audio ${VENDOR_SDK_LIBRARIES} gcc_s hisicompat) 99 | 100 | endif() 101 | 102 | -------------------------------------------------------------------------------- /aux/string.h: -------------------------------------------------------------------------------- 1 | #ifndef __AUX_STRING_H__ 2 | #define __AUX_STRING_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #if 1 14 | typedef struct { size_t size; char *data; } strt, *strp; 15 | 16 | #define aux_string(s) { sizeof(s) - 1, s } 17 | #define aux_null_string { 0, NULL } 18 | extern strt aux_empty_string; 19 | 20 | #define CR 0x0d 21 | #define LF 0x0a 22 | #define CRLF "\r\n" 23 | 24 | #define QUOTES_NAME(val) #val 25 | #define QUOTES_DATA(val) QUOTES_NAME(val) 26 | #define CONCAT_NAME(a,b) a##b 27 | #define CONCAT_DATA(a,b) CONCAT_NAME(a,b) 28 | 29 | #define aux_clrptr(p) memset((p),0,sizeof(*(p))) 30 | #define aux_clrvec(p,n) memset((p),0,sizeof(*(p))*(n)) 31 | #define aux_clrmem(p,n) memset((p),0,(n)) 32 | 33 | #define aux_memcpy(d,s,n) ((memcpy(d,s,n))) 34 | #define aux_cpymsz(d,s,n) ((memcpy(d,s,n),(n))) 35 | #define aux_cpymem(d,s,n) (((char *)memcpy(d,s,n))+(n)) 36 | 37 | /* rowsof - static allocated arrays only */ 38 | 39 | #define aux_bitsof(x) (sizeof(x) * 8) 40 | #define aux_rowsof(x) (sizeof(x)/sizeof((x)[0])) 41 | #define aux_member(t,n) (((t*)0)->(n)) 42 | #define aux_memberof(t,n,p) (((t*)(((unsigned char *)(p))-offsetof(t,n)))) 43 | #define aux_mebitsof(t,n) (aux_bitsof(aux_member(t,n))) 44 | #define aux_mesizeof(t,n) (sizeof(aux_member(t,n))) 45 | #define aux_metypeof(t,n) (typeof(aux_member(t,n))) 46 | #endif 47 | 48 | /* ----------------- */ 49 | 50 | #define aux_strerror(err) aux_strerror_r(err, (char *) alloca(4096), 4096) 51 | 52 | static inline 53 | const char* aux_strerror_r(int err, char* data, size_t size) 54 | { 55 | #if !defined(__USE_GNU) || defined(__FreeBSD__) 56 | if (0 != strerror_r(err, data, size)) return "XSI strerror_r returned error"; 57 | return data; 58 | #else 59 | return strerror_r(err, data, size); 60 | #endif /* __USE_GNU */ 61 | } 62 | 63 | /* ----------------- */ 64 | 65 | extern const unsigned char aux_ctypes_table [UCHAR_MAX + 1]; 66 | extern const unsigned char aux_ch2dig_table [UCHAR_MAX + 1]; 67 | 68 | #define aux_ctypes(c) aux_ctypes_table[(unsigned char) (c)] 69 | #define aux_ch2dig(c) aux_ch2dig_table[(unsigned char) (c)] 70 | 71 | #define AUX_SPACE 0x01 /* space */ 72 | #define AUX_OCTAL 0x02 /* octal */ 73 | #define AUX_DECAL 0x04 /* digit */ 74 | #define AUX_HEXUP 0x08 /* hexup */ 75 | #define AUX_HEXLO 0x10 /* hexlo */ 76 | #define AUX_UPPER 0x20 /* upper */ 77 | #define AUX_LOWER 0x40 /* lower */ 78 | 79 | #define aux_isspace(c) (aux_ctypes(c) & (AUX_SPACE)) 80 | #define aux_isoctal(c) (aux_ctypes(c) & (AUX_OCTAL)) 81 | #define aux_isdecal(c) (aux_ctypes(c) & (AUX_OCTAL|AUX_DECAL)) 82 | #define aux_ishexit(c) (aux_ctypes(c) & (AUX_OCTAL|AUX_DECAL|AUX_HEXUP|AUX_HEXLO)) 83 | #define aux_ishexup(c) (aux_ctypes(c) & (AUX_HEXUP)) 84 | #define aux_ishexlo(c) (aux_ctypes(c) & (AUX_HEXLO)) 85 | #define aux_isupper(c) (aux_ctypes(c) & (AUX_HEXUP|AUX_UPPER)) 86 | #define aux_islower(c) (aux_ctypes(c) & (AUX_HEXLO|AUX_LOWER)) 87 | #define aux_isalpha(c) (aux_ctypes(c) & (AUX_HEXUP|AUX_HEXLO|AUX_UPPER|AUX_LOWER)) 88 | #define aux_isalnum(c) (aux_ctypes(c) & (AUX_OCTAL|AUX_DECAL|AUX_HEXUP|AUX_HEXLO|AUX_UPPER|AUX_LOWER)) 89 | #define aux_tolower(c) ((unsigned char) (((c) >= 'A' && (c) <= 'Z') ? ((c) | 0x20) : (c))) 90 | #define aux_toupper(c) ((unsigned char) (((c) >= 'a' && (c) <= 'z') ? ((c) & ~0x20) : (c))) 91 | 92 | #define hex_hi(x) "0123456789abcdef" [((unsigned char) (x)) >> 4] 93 | #define hex_lo(x) "0123456789abcdef" [((unsigned char) (x)) & 0xf] 94 | #define HEX_hi(x) "0123456789ABCDEF" [((unsigned char) (x)) >> 4] 95 | #define HEX_lo(x) "0123456789ABCDEF" [((unsigned char) (x)) & 0xf] 96 | #define hex_pk(l,r) ((*l++ = hex_hi(r)), (*l++ = hex_lo(r))) 97 | #define HEX_pk(l,r) ((*l++ = HEX_hi(r)), (*l++ = HEX_lo(r))) 98 | 99 | static inline 100 | int aux_bin2str(char *dest, const char *data, size_t size) 101 | { 102 | for (; size--; ++data) 103 | { 104 | HEX_pk(dest,*data); 105 | } 106 | 107 | return 0; 108 | } 109 | 110 | static inline 111 | int aux_str2bin(char *dest, const char *data, size_t size) 112 | { 113 | unsigned char dig; 114 | 115 | for (;; ++dest) 116 | { 117 | if (!size--) break; 118 | if (16 <= (dig = aux_ch2dig(*data++))) return -1; 119 | *dest |= (dig & 0x0f) << 4; 120 | 121 | if (!size--) break; 122 | if (16 <= (dig = aux_ch2dig(*data++))) return -1; 123 | *dest |= dig & 0x0f; 124 | } 125 | 126 | return 0; 127 | } 128 | 129 | char *aux_stristr(const char *s, const char *n); /* search for [n] in [s] ignoring case */ 130 | char *aux_strnstr(const char *s, const char *n, size_t len); /* search for [n] in first [len] bytes of [s] */ 131 | char *aux_strxstr(const char *s, const char *n, size_t len); /* search for [n] in first [len] bytes of [s] ignoring case */ 132 | 133 | static inline 134 | char *aux_memmem(const char *m, size_t sz_m, const char *n, size_t sz_n) 135 | { 136 | const char *bm, *em, *bn, *en; 137 | 138 | if (!m || !sz_m) return NULL; 139 | if (!n || !sz_n) return (char *) m; 140 | if (sz_m < sz_n) return NULL; 141 | 142 | bm = m; em = bm + sz_m; 143 | bn = n; en = bn + sz_n; 144 | 145 | for (; bm < em; ++bm) 146 | { 147 | if (*bm == *bn) 148 | { 149 | const char *pm, *pn; 150 | 151 | for (pm = bm, pn = bn; pm < em && pn < en; ++pm, ++pn) 152 | { 153 | if (*pm != *pn) break; 154 | } 155 | 156 | if (pn == en) return (char *) bm; 157 | } 158 | } 159 | 160 | return NULL; 161 | } 162 | 163 | /* two functions below will add terminating 0 byte! */ 164 | size_t aux_urlenc(char *dst, const char *src, size_t sz_src); 165 | size_t aux_urldec(char *dst, const char *src, size_t sz_src); 166 | 167 | #ifdef __cplusplus 168 | } /* extern "C" */ 169 | #endif 170 | 171 | #endif /* __AUX_STRING_H__ */ 172 | -------------------------------------------------------------------------------- /hitiny/hitiny_vda.c: -------------------------------------------------------------------------------- 1 | #include "hitiny_vda.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | typedef struct vda_chn_info_s 13 | { 14 | int fd; 15 | unsigned phy_addr; 16 | void* ptr; 17 | unsigned sz; 18 | } vda_chn_info_t; 19 | 20 | static vda_chn_info_t vda_chns[VDA_CHN_NUM_MAX] = { -1 }; 21 | 22 | void hitiny_vda_init() 23 | { 24 | memset(vda_chns, 0, VDA_CHN_NUM_MAX * sizeof(vda_chn_info_t)); 25 | for (int i = 0; i < VDA_CHN_NUM_MAX; i++) vda_chns[i].fd = -1; 26 | } 27 | 28 | void hitiny_vda_done() 29 | { 30 | for (int i = 0; i < VDA_CHN_NUM_MAX; i++) 31 | { 32 | if (vda_chns[i].fd >= 0) close(vda_chns[i].fd); 33 | } 34 | 35 | memset(vda_chns, 0, VDA_CHN_NUM_MAX * sizeof(vda_chn_info_t)); 36 | for (int i = 0; i < VDA_CHN_NUM_MAX; i++) vda_chns[i].fd = -1; 37 | } 38 | 39 | int hitiny_MPI_VDA_GetFd(unsigned VdaChn) 40 | { 41 | if (VDA_CHN_NUM_MAX <= VdaChn) return 0xa0098002; 42 | 43 | if (vda_chns[VdaChn].fd >=0) return vda_chns[VdaChn].fd; 44 | 45 | int fd = hitiny_open_dev("/dev/vda"); 46 | if (fd < 0) 47 | { 48 | log_error("Can't open /dev/vda: %s (%d)", strerror(errno), errno); 49 | return fd; 50 | } 51 | 52 | unsigned param = VdaChn; 53 | int res = ioctl(fd, 0x40044d0d, ¶m); 54 | if (res) 55 | { 56 | close(fd); 57 | return res; 58 | } 59 | 60 | vda_chns[VdaChn].fd = fd; 61 | 62 | return fd; 63 | } 64 | 65 | int hitiny_MPI_VDA_CreateChn(VDA_CHN VdaChn, const VDA_CHN_ATTR_S *pstAttr) 66 | { 67 | int vda_chn_fd = hitiny_MPI_VDA_GetFd(VdaChn); 68 | if (vda_chn_fd < 0) return vda_chn_fd; 69 | 70 | int ret = ioctl(vda_chn_fd, 0x40a84d00, pstAttr); 71 | if (ret) 72 | { 73 | log_error("Can't ioctl 0x40a84d00: 0x%x", ret); 74 | return ret; 75 | } 76 | 77 | unsigned param[2]; 78 | ret = ioctl(vda_chn_fd, 0xc0084d0e, param); 79 | if (ret) 80 | { 81 | log_error("Can't ioctl 0xc0084d0e: 0x%x", ret); 82 | return ret; 83 | } 84 | 85 | // DBG 86 | //log_info("GOT mem at 0x%x, sz=%u", param[0], param[1]); 87 | vda_chns[VdaChn].phy_addr = param[0]; 88 | vda_chns[VdaChn].sz = param[1]; 89 | 90 | void* ptr = hitiny_MPI_SYS_Mmap(vda_chns[VdaChn].phy_addr, vda_chns[VdaChn].sz); 91 | if (ptr == (void*)(-1)) 92 | { 93 | log_error("Can't mmap: (%d) %s", errno, strerror(errno)); 94 | ioctl(vda_chn_fd, 0X4d01); 95 | return 0xa009800c; 96 | } 97 | 98 | vda_chns[VdaChn].ptr = ptr; 99 | 100 | //log_info("vda chnl ptr is 0x%x", vda_chns[VdaChn].ptr); 101 | return 0; 102 | } 103 | 104 | int hitiny_MPI_VDA_DestroyChn(VDA_CHN VdaChn) 105 | { 106 | int vda_chn_fd = hitiny_MPI_VDA_GetFd(VdaChn); 107 | 108 | if (vda_chn_fd < 0) return vda_chn_fd; 109 | 110 | int ret = 0; 111 | 112 | if (vda_chns[VdaChn].ptr) 113 | { 114 | ret = hitiny_MPI_SYS_Munmap(vda_chns[VdaChn].ptr, vda_chns[VdaChn].sz); 115 | vda_chns[VdaChn].phy_addr = 0; 116 | vda_chns[VdaChn].ptr = 0; 117 | vda_chns[VdaChn].sz = 0; 118 | if (ret) log_error("munmap at destroy VDA chnl failed: %s (%d)", strerror(errno), errno); 119 | } 120 | 121 | ret = ioctl(vda_chn_fd, 0x4d01); 122 | 123 | close(vda_chn_fd); 124 | vda_chns[VdaChn].fd = -1; 125 | return ret; 126 | } 127 | 128 | int hitiny_MPI_VDA_StartRecvPic(VDA_CHN VdaChn) 129 | { 130 | int vda_chn_fd = hitiny_MPI_VDA_GetFd(VdaChn); 131 | 132 | if (vda_chn_fd < 0) return vda_chn_fd; 133 | 134 | return ioctl(vda_chn_fd, 0x4d06); 135 | } 136 | 137 | int hitiny_MPI_VDA_StopRecvPic(VDA_CHN VdaChn) 138 | { 139 | int vda_chn_fd = hitiny_MPI_VDA_GetFd(VdaChn); 140 | 141 | if (vda_chn_fd < 0) return vda_chn_fd; 142 | 143 | return ioctl(vda_chn_fd, 0x4d07); 144 | } 145 | 146 | struct vda_get_data_param_t 147 | { 148 | VDA_DATA_S vda_data; 149 | HI_BOOL blocking; 150 | uint32_t reserved[5]; 151 | }; 152 | 153 | int hitiny_MPI_VDA_GetData(VDA_CHN VdaChn, VDA_DATA_S *pstVdaData, HI_BOOL bBlock) 154 | { 155 | int fd = hitiny_MPI_VDA_GetFd(VdaChn); 156 | 157 | if (fd < 0) return fd; 158 | 159 | if (!pstVdaData) return 0xa0098006; 160 | 161 | struct vda_get_data_param_t param; 162 | memset(¶m, 0, sizeof(struct vda_get_data_param_t)); 163 | param.blocking = bBlock; 164 | 165 | int ret = ioctl(fd, 0xc0504d08, ¶m); 166 | 167 | if (ret) return ret; 168 | 169 | // log_info("Got VDA DATA: enWorkMode = %u, enMbSize = %u, razmer %ux%u", 170 | // param.vda_data.enWorkMode, param.vda_data.enMbSize, 171 | // param.vda_data.u32MbWidth, param.vda_data.u32MbHeight); 172 | 173 | *pstVdaData = param.vda_data; 174 | if (param.vda_data.enWorkMode == VDA_WORK_MODE_MD) 175 | { 176 | if (param.vda_data.unData.stMdData.bMbSadValid) 177 | { 178 | pstVdaData->unData.stMdData.stMbSadData.pAddr = vda_chns[VdaChn].ptr + (unsigned)pstVdaData->unData.stMdData.stMbSadData.pAddr - vda_chns[VdaChn].phy_addr; 179 | } 180 | if (param.vda_data.unData.stMdData.bObjValid) 181 | { 182 | pstVdaData->unData.stMdData.stObjData.pstAddr = (VDA_OBJ_S *)(vda_chns[VdaChn].ptr + (unsigned)pstVdaData->unData.stMdData.stObjData.pstAddr - vda_chns[VdaChn].phy_addr); 183 | } 184 | } 185 | 186 | return 0; 187 | } 188 | 189 | int hitiny_MPI_VDA_ReleaseData(VDA_CHN VdaChn, const VDA_DATA_S* pstVdaData) 190 | { 191 | int fd = hitiny_MPI_VDA_GetFd(VdaChn); 192 | if (fd < 0) return fd; 193 | 194 | if (!pstVdaData) return 0xa0098006; 195 | 196 | return ioctl(fd, 0x40484d09, pstVdaData); 197 | } 198 | 199 | -------------------------------------------------------------------------------- /test/test_md.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | int stop_flag = 0; 17 | 18 | void action_on_signal(int signum) 19 | { 20 | log_info("STOP"); 21 | stop_flag = 1; 22 | } 23 | 24 | void print_md_data(const VDA_DATA_S *pstVdaData) 25 | { 26 | if (pstVdaData->unData.stMdData.bObjValid && pstVdaData->unData.stMdData.stObjData.u32ObjNum > 0) 27 | { 28 | log_info("ObjNum=%d, IndexOfMaxObj=%d, SizeOfMaxObj=%d, SizeOfTotalObj=%d", \ 29 | pstVdaData->unData.stMdData.stObjData.u32ObjNum, \ 30 | pstVdaData->unData.stMdData.stObjData.u32IndexOfMaxObj, \ 31 | pstVdaData->unData.stMdData.stObjData.u32SizeOfMaxObj,\ 32 | pstVdaData->unData.stMdData.stObjData.u32SizeOfTotalObj); 33 | for (int i=0; iunData.stMdData.stObjData.u32ObjNum; i++) 34 | { 35 | VDA_OBJ_S *pstVdaObj = pstVdaData->unData.stMdData.stObjData.pstAddr + i; 36 | log_info("[%d]\t left=%d, top=%d, right=%d, bottom=%d", i, \ 37 | pstVdaObj->u16Left, pstVdaObj->u16Top, \ 38 | pstVdaObj->u16Right, pstVdaObj->u16Bottom); 39 | } 40 | } 41 | 42 | if (!pstVdaData->unData.stMdData.bPelsNumValid) 43 | { 44 | log_info("bMbObjValid = FALSE"); 45 | } 46 | else 47 | { 48 | log_info("AlarmPixelCount=%d", pstVdaData->unData.stMdData.u32AlarmPixCnt); 49 | } 50 | } 51 | 52 | void test_RUN() 53 | { 54 | unsigned VdaChn = 0; 55 | 56 | fd_set read_fds; 57 | struct timeval TimeoutVal; 58 | 59 | int fd = hitiny_MPI_VDA_GetFd(VdaChn); 60 | if (fd < 0) return; 61 | 62 | int maxfd = fd; 63 | 64 | while (!stop_flag) 65 | { 66 | FD_ZERO(&read_fds); 67 | FD_SET(fd, &read_fds); 68 | 69 | TimeoutVal.tv_sec = 2; 70 | TimeoutVal.tv_usec = 0; 71 | int s32Ret = select(maxfd + 1, &read_fds, NULL, NULL, &TimeoutVal); 72 | if (s32Ret < 0) 73 | { 74 | log_error("select() error"); 75 | return; 76 | } 77 | else if (s32Ret == 0) 78 | { 79 | log_info("TIMEOUT"); 80 | break; 81 | } 82 | 83 | if (!FD_ISSET(fd, &read_fds)) 84 | { 85 | log_error("WHAT???"); 86 | return; 87 | } 88 | 89 | VDA_DATA_S stVdaData; 90 | 91 | s32Ret = hitiny_MPI_VDA_GetData(VdaChn, &stVdaData, HI_FALSE); 92 | 93 | if (!s32Ret) 94 | { 95 | print_md_data(&stVdaData); 96 | } 97 | else 98 | { 99 | log_error("MPI_VDA_GetData returned error 0x%x", s32Ret); 100 | } 101 | s32Ret = hitiny_MPI_VDA_ReleaseData(VdaChn,&stVdaData); 102 | } 103 | } 104 | 105 | void test_md() 106 | { 107 | unsigned VdaChn = 0; 108 | 109 | VDA_CHN_ATTR_S stVdaChnAttr; 110 | 111 | stVdaChnAttr.enWorkMode = VDA_WORK_MODE_MD; 112 | stVdaChnAttr.u32Width = 256; 113 | stVdaChnAttr.u32Height = 144; 114 | 115 | stVdaChnAttr.unAttr.stMdAttr.enVdaAlg = VDA_ALG_REF; 116 | stVdaChnAttr.unAttr.stMdAttr.enMbSize = VDA_MB_16PIXEL; 117 | stVdaChnAttr.unAttr.stMdAttr.enMbSadBits = VDA_MB_SAD_8BIT; 118 | stVdaChnAttr.unAttr.stMdAttr.enRefMode = VDA_REF_MODE_DYNAMIC; 119 | stVdaChnAttr.unAttr.stMdAttr.u32MdBufNum = 8; 120 | stVdaChnAttr.unAttr.stMdAttr.u32VdaIntvl = 5; 121 | stVdaChnAttr.unAttr.stMdAttr.u32BgUpSrcWgt = 128; 122 | stVdaChnAttr.unAttr.stMdAttr.u32SadTh = 2000; 123 | stVdaChnAttr.unAttr.stMdAttr.u32ObjNumMax = 16; 124 | 125 | int fd = hitiny_MPI_VDA_GetFd(VdaChn); 126 | if(fd < 0) 127 | { 128 | log_error("Can't open VDA chn: 0x%x", fd); 129 | return; 130 | } 131 | 132 | hitiny_MPI_VDA_DestroyChn(VdaChn); 133 | 134 | int s32Ret = hitiny_MPI_VDA_CreateChn(VdaChn, &stVdaChnAttr); 135 | if(s32Ret != HI_SUCCESS) 136 | { 137 | log_error("Can't create VDA chn: 0x%x", s32Ret); 138 | return; 139 | } 140 | 141 | log_info("going to bind"); 142 | 143 | s32Ret = hitiny_sys_bind_VI_VDA(0, 1, VdaChn); 144 | if(s32Ret != HI_SUCCESS) 145 | { 146 | log_error("Can't bind VDA to VI: 0x%x", s32Ret); 147 | hitiny_sys_unbind_VI_VDA(0, 1, VdaChn); 148 | hitiny_MPI_VDA_DestroyChn(VdaChn); 149 | return; 150 | } 151 | 152 | log_info("going to start recv"); 153 | s32Ret = hitiny_MPI_VDA_StartRecvPic(VdaChn); 154 | if(s32Ret != HI_SUCCESS) 155 | { 156 | log_error("Can't HI_MPI_VDA_StartRecvPic: 0x%x", s32Ret); 157 | hitiny_MPI_VDA_DestroyChn(VdaChn); 158 | return; 159 | } 160 | 161 | log_info("VDA init OK!"); 162 | test_RUN(); 163 | 164 | s32Ret = hitiny_MPI_VDA_StopRecvPic(VdaChn); 165 | if(s32Ret != HI_SUCCESS) 166 | { 167 | log_error("Can't VDA chnl stop recv pic: 0x%x", s32Ret); 168 | } 169 | log_info("done StopRecvPic"); 170 | 171 | s32Ret = hitiny_sys_unbind_VI_VDA(0, 1, VdaChn); 172 | if(s32Ret != HI_SUCCESS) 173 | { 174 | log_error("Can't unbind VDA chn: 0x%x", s32Ret); 175 | } 176 | log_info("done unbind_VI_VDA"); 177 | 178 | s32Ret = hitiny_MPI_VDA_DestroyChn(VdaChn); 179 | if(s32Ret != HI_SUCCESS) 180 | { 181 | log_error("Can't destroy VDA chn: 0x%x", s32Ret); 182 | } 183 | log_info("done DestroyChn"); 184 | } 185 | 186 | 187 | int main(int argc, char** argv) 188 | { 189 | hitiny_vda_init(); 190 | 191 | signal(SIGINT, action_on_signal); 192 | 193 | test_md(); 194 | 195 | hitiny_vda_done(); 196 | 197 | return 0; 198 | } 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /libev/ev_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libev win32 compatibility cruft (_not_ a backend) 3 | * 4 | * Copyright (c) 2007,2008,2009 Marc Alexander Lehmann 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modifica- 8 | * tion, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 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 ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26 | * OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * Alternatively, the contents of this file may be used under the terms of 29 | * the GNU General Public License ("GPL") version 2 or any later version, 30 | * in which case the provisions of the GPL are applicable instead of 31 | * the above. If you wish to allow the use of your version of this file 32 | * only under the terms of the GPL and not to allow others to use your 33 | * version of this file under the BSD license, indicate your decision 34 | * by deleting the provisions above and replace them with the notice 35 | * and other provisions required by the GPL. If you do not delete the 36 | * provisions above, a recipient may use your version of this file under 37 | * either the BSD or the GPL. 38 | */ 39 | 40 | #ifdef _WIN32 41 | 42 | /* note: the comment below could not be substantiated, but what would I care */ 43 | /* MSDN says this is required to handle SIGFPE */ 44 | /* my wild guess would be that using something floating-pointy is required */ 45 | /* for the crt to do something about it */ 46 | volatile double SIGFPE_REQ = 0.0f; 47 | 48 | static SOCKET 49 | ev_tcp_socket (void) 50 | { 51 | #if EV_USE_WSASOCKET 52 | return WSASocket (AF_INET, SOCK_STREAM, 0, 0, 0, 0); 53 | #else 54 | return socket (AF_INET, SOCK_STREAM, 0); 55 | #endif 56 | } 57 | 58 | /* oh, the humanity! */ 59 | static int 60 | ev_pipe (int filedes [2]) 61 | { 62 | struct sockaddr_in addr = { 0 }; 63 | int addr_size = sizeof (addr); 64 | struct sockaddr_in adr2; 65 | int adr2_size = sizeof (adr2); 66 | SOCKET listener; 67 | SOCKET sock [2] = { -1, -1 }; 68 | 69 | if ((listener = ev_tcp_socket ()) == INVALID_SOCKET) 70 | return -1; 71 | 72 | addr.sin_family = AF_INET; 73 | addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 74 | addr.sin_port = 0; 75 | 76 | if (bind (listener, (struct sockaddr *)&addr, addr_size)) 77 | goto fail; 78 | 79 | if (getsockname (listener, (struct sockaddr *)&addr, &addr_size)) 80 | goto fail; 81 | 82 | if (listen (listener, 1)) 83 | goto fail; 84 | 85 | if ((sock [0] = ev_tcp_socket ()) == INVALID_SOCKET) 86 | goto fail; 87 | 88 | if (connect (sock [0], (struct sockaddr *)&addr, addr_size)) 89 | goto fail; 90 | 91 | /* TODO: returns INVALID_SOCKET on winsock accept, not < 0. fix it */ 92 | /* when convenient, probably by just removing error checking altogether? */ 93 | if ((sock [1] = accept (listener, 0, 0)) < 0) 94 | goto fail; 95 | 96 | /* windows vista returns fantasy port numbers for sockets: 97 | * example for two interconnected tcp sockets: 98 | * 99 | * (Socket::unpack_sockaddr_in getsockname $sock0)[0] == 53364 100 | * (Socket::unpack_sockaddr_in getpeername $sock0)[0] == 53363 101 | * (Socket::unpack_sockaddr_in getsockname $sock1)[0] == 53363 102 | * (Socket::unpack_sockaddr_in getpeername $sock1)[0] == 53365 103 | * 104 | * wow! tridirectional sockets! 105 | * 106 | * this way of checking ports seems to work: 107 | */ 108 | if (getpeername (sock [0], (struct sockaddr *)&addr, &addr_size)) 109 | goto fail; 110 | 111 | if (getsockname (sock [1], (struct sockaddr *)&adr2, &adr2_size)) 112 | goto fail; 113 | 114 | errno = WSAEINVAL; 115 | if (addr_size != adr2_size 116 | || addr.sin_addr.s_addr != adr2.sin_addr.s_addr /* just to be sure, I mean, it's windows */ 117 | || addr.sin_port != adr2.sin_port) 118 | goto fail; 119 | 120 | closesocket (listener); 121 | 122 | #if EV_SELECT_IS_WINSOCKET 123 | filedes [0] = EV_WIN32_HANDLE_TO_FD (sock [0]); 124 | filedes [1] = EV_WIN32_HANDLE_TO_FD (sock [1]); 125 | #else 126 | /* when select isn't winsocket, we also expect socket, connect, accept etc. 127 | * to work on fds */ 128 | filedes [0] = sock [0]; 129 | filedes [1] = sock [1]; 130 | #endif 131 | 132 | return 0; 133 | 134 | fail: 135 | closesocket (listener); 136 | 137 | if (sock [0] != INVALID_SOCKET) closesocket (sock [0]); 138 | if (sock [1] != INVALID_SOCKET) closesocket (sock [1]); 139 | 140 | return -1; 141 | } 142 | 143 | #undef pipe 144 | #define pipe(filedes) ev_pipe (filedes) 145 | 146 | #define EV_HAVE_EV_TIME 1 147 | ev_tstamp 148 | ev_time (void) 149 | { 150 | FILETIME ft; 151 | ULARGE_INTEGER ui; 152 | 153 | GetSystemTimeAsFileTime (&ft); 154 | ui.u.LowPart = ft.dwLowDateTime; 155 | ui.u.HighPart = ft.dwHighDateTime; 156 | 157 | /* msvc cannot convert ulonglong to double... yes, it is that sucky */ 158 | return (LONGLONG)(ui.QuadPart - 116444736000000000) * 1e-7; 159 | } 160 | 161 | #endif 162 | 163 | --------------------------------------------------------------------------------