├── .gitignore ├── LICENSE ├── README.md ├── box.png ├── examples ├── meshes │ ├── box.h │ ├── pony.h │ └── teapot.h ├── sdl │ ├── Makefile │ └── main.c ├── stm32f429-discovery │ ├── .gdbinit │ ├── Makefile │ ├── main.c │ ├── startup_stm32f429_439xx.S │ ├── stm32f429zi_flash.ld │ ├── stm32f4xx_conf.h │ ├── stm32f4xx_it.c │ ├── stm32f4xx_it.h │ └── system_stm32f4xx.c └── textures │ ├── box_texture.h │ ├── nyan.h │ └── twilight.h ├── libs ├── r3d │ ├── r3d.c │ ├── r3d.h │ └── r3d_math.h ├── r3dfb-sdl │ ├── r3dfb.c │ └── r3dfb.h └── r3dfb-stm32f429-discovery │ ├── r3dfb.c │ └── r3dfb.h ├── nyanpot.png └── pony.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | 5 | # Libraries 6 | *.lib 7 | *.a 8 | 9 | # Shared objects (inc. Windows DLLs) 10 | *.dll 11 | *.so 12 | *.so.* 13 | *.dylib 14 | 15 | # Executables 16 | *.exe 17 | *.out 18 | *.app 19 | example-sdl 20 | example-stm32f429-discovery 21 | 22 | # Foo 23 | *.lst 24 | *.elf 25 | *~ 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | # Released under MIT License 2 | 3 | Copyright 2020 Andreas Mantler 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | libr3d 2 | ====== 3 | 4 | A small realtime software rendering library 5 | 6 | It was written to display some fun realtime 3D graphics on the STM32F429-Discovery evaluation board. 7 | 8 | ![Nyanpot](https://github.com/ands/libr3d/raw/master/nyanpot.png) 9 | ![Box](https://github.com/ands/libr3d/raw/master/box.png) 10 | ![Pony](https://github.com/ands/libr3d/raw/master/pony.png) 11 | 12 | TODO: 13 | 14 | - Correct perspective interpolation 15 | 16 | - Alpha blending 17 | 18 | - Alpha testing 19 | 20 | - Scan line triangle drawing? 21 | 22 | - ... 23 | -------------------------------------------------------------------------------- /box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ands/libr3d/d421d44757e14b8120086a6b1912bc6bea0f6998/box.png -------------------------------------------------------------------------------- /examples/sdl/Makefile: -------------------------------------------------------------------------------- 1 | CC = clang 2 | CFLAGS = -Wall -c `pkg-config --cflags sdl2` -I../../libs/r3d/ -I../../libs/r3dfb-sdl/ -I../meshes/ -I../textures/ -Wno-missing-braces 3 | LDFLAGS = `pkg-config --libs sdl2` -lm 4 | EXE = example-sdl 5 | 6 | all: $(EXE) 7 | 8 | $(EXE): main.o r3d.o r3dfb.o 9 | $(CC) $(LDFLAGS) main.o r3d.o r3dfb.o -o $@ 10 | 11 | main.o: main.c 12 | $(CC) $(CFLAGS) $< -o $@ 13 | 14 | r3d.o: ../../libs/r3d/r3d.c 15 | $(CC) $(CFLAGS) $< -o $@ 16 | 17 | r3dfb.o: ../../libs/r3dfb-sdl/r3dfb.c 18 | $(CC) $(CFLAGS) $< -o $@ 19 | 20 | clean: 21 | rm *.o && rm $(EXE) 22 | -------------------------------------------------------------------------------- /examples/sdl/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "r3d.h" 7 | #include "r3dfb.h" 8 | 9 | // vertex format 10 | typedef struct 11 | { 12 | uint16_t x, y, z; 13 | uint8_t nx, ny, nz; 14 | uint8_t u, v; 15 | } vertex_t; 16 | 17 | #include "teapot.h" // mesh 18 | #include "nyan.h" // texture 19 | 20 | static const r3d_drawcall_t mesh = 21 | { 22 | R3D_PRIMITIVE_TYPE_TRIANGLES, 23 | vertices0, // vertex data 24 | sizeof(vertex_t), // vertex size 25 | sizeof(vertices0) / sizeof(vertex_t), // count 26 | 0 // indices 27 | }; 28 | 29 | static mat4_t model, view, projection, mv, mvp; 30 | 31 | // shader 32 | typedef struct 33 | { 34 | vec3_t position; 35 | vec3_t normal; 36 | vec2_t uv; 37 | } vs_to_fs_t; 38 | 39 | static void vertex_shader(const vertex_t *in, vs_to_fs_t *out) 40 | { 41 | // decode vertex 42 | const vec3_t pc = { 0.5f, 0.5f, 0.5f }, nc = { 1.0f, 1.0f, 1.0f }; 43 | const float pi = 1.0f / 65535.0f, ni = 2.0f / 255.0f, uvi = 1.0f / 255.0f; 44 | vec3_t position = vec3_sub(vec3_mul(vec3(in->x, in->y, in->z), pi), pc); 45 | vec3_t normal = vec3_sub(vec3_mul(vec3(in->nx, in->ny, in->nz), ni), nc); 46 | vec2_t uv = vec2_mul(vec2(in->u, in->v), uvi); 47 | // transform vertex 48 | out->position = mat4_transform_position(mvp, position); 49 | out->normal = mat4_transform_vector(mv, normal); 50 | out->uv = uv; 51 | } 52 | 53 | static vec4_t fragment_shader(const vs_to_fs_t *in) 54 | { 55 | const vec3_t E = { 0, 0, 1 }; 56 | const vec3_t L = { -0.577350269f, 0.577350269f, 0.577350269f }; 57 | vec3_t N = vec3_normalize(in->normal); 58 | vec3_t H = vec3_normalize(vec3_add(E, L)); 59 | 60 | const float ambient = 0.05f; 61 | float diffuse = vec3_dot(N, L) * 0.6f; 62 | float specular = vec3_dot(N, H); 63 | specular *= specular; specular *= specular; specular *= specular; 64 | specular *= specular; specular *= specular; specular *= specular * 0.6f; 65 | 66 | vec3_t c = r3d_texture_nearest((r3d_texture_t*)&nyan, in->uv); // read texel 67 | return vec4(ambient + diffuse * c.r + specular, 68 | ambient + diffuse * c.g + specular, 69 | ambient + diffuse * c.b + specular, 1.0f); 70 | } 71 | 72 | static r3d_shader_t shader = 73 | { 74 | (r3d_vertexshader_func)vertex_shader, 75 | (r3d_fragmentshader_func)fragment_shader, 76 | sizeof(vs_to_fs_t) / sizeof(float) 77 | }; 78 | 79 | int main(int argc, char **argv) 80 | { 81 | r3dfb_init(); 82 | 83 | projection = mat4_perspective(60.0f, (float)R3DFB_PIXEL_WIDTH / (float)R3DFB_PIXEL_HEIGHT, 0.5f, 5.0f); 84 | view = mat4_lookat(vec3(0.0f, 0.25f, 1.5f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f)); 85 | 86 | r3d_viewport(0, 0, R3DFB_PIXEL_WIDTH, R3DFB_PIXEL_HEIGHT); 87 | r3d_backface_culling = R3D_ENABLE; 88 | r3d_primitive_winding = R3D_PRIMITIVE_WINDING_CW; 89 | 90 | int frame = 0; 91 | 92 | while(42) 93 | { 94 | model = mat4_mul( 95 | mat4_rotation(frame, vec3(1.0f, 0.0f, 0.0f)), 96 | mat4_rotation(frame++, vec3(0.0f, 1.0f, 0.0f))); 97 | mv = mat4_mul(view, model); 98 | mvp = mat4_mul(projection, mv); 99 | 100 | r3dfb_clear(); 101 | r3d_shader = shader; 102 | r3d_draw(&mesh); 103 | r3dfb_swap_buffers(); 104 | } 105 | 106 | return 0; 107 | } 108 | -------------------------------------------------------------------------------- /examples/stm32f429-discovery/.gdbinit: -------------------------------------------------------------------------------- 1 | define reload 2 | kill 3 | monitor jtag_reset 4 | load 5 | end 6 | 7 | target extended localhost:4242 8 | load 9 | -------------------------------------------------------------------------------- /examples/stm32f429-discovery/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT=example-stm32f429-discovery 2 | 3 | EXECUTABLE=$(PROJECT).elf 4 | BIN_IMAGE=$(PROJECT).bin 5 | HEX_IMAGE=$(PROJECT).hex 6 | 7 | # set the path to your STM32F429I-Discovery_FW_V1.0.1 here: 8 | STDP=/home/ands/warpzone/arm-stm32/boards/stm32f429-discovery/STM32F429I-Discovery_FW_V1.0.1/ 9 | 10 | CC=arm-none-eabi-gcc 11 | OBJCOPY=arm-none-eabi-objcopy 12 | 13 | LIBS=-lm 14 | CFLAGS=-g -std=c99 -O3 -mlittle-endian -mthumb 15 | CFLAGS+=-mcpu=cortex-m4 -DSTM32F429_439xx 16 | #CFLAGS+=-nostartfiles 17 | #CFLAGS+=-ffreestanding 18 | #CFLAGS+=-nostdlib 19 | #CFLAGS+=--gc-sections 20 | 21 | #FPU 22 | CFLAGS+=-mfpu=fpv4-sp-d16 -mfloat-abi=hard 23 | CFLAGS+=-DARM_MATH_CM4 -D__FPU_PRESENT 24 | 25 | # to run from FLASH 26 | CFLAGS+=-DVECT_TAB_FLASH 27 | CFLAGS+=-Wl,-T,stm32f429zi_flash.ld 28 | 29 | #PROJECT SOURCE 30 | CFLAGS+=-I. 31 | SOURCE=*.c 32 | #LIB r3d 33 | CFLAGS+=-I../../libs/r3d/ 34 | SOURCE+=../../libs/r3d/*.c 35 | #LIB r3dfb 36 | CFLAGS+=-I../../libs/r3dfb-stm32f429-discovery/ 37 | SOURCE+=../../libs/r3dfb-stm32f429-discovery/*.c 38 | #example data 39 | CFLAGS+=-I../meshes/ 40 | CFLAGS+=-I../textures/ 41 | #L3GD20 default callback 42 | #CFLAGS+=-DUSE_DEFAULT_TIMEOUT_CALLBACK 43 | 44 | #STARTUP FILE 45 | SOURCE+=startup_stm32f429_439xx.S 46 | 47 | #CMSIS 48 | CFLAGS+=-I$(STDP)/Libraries/CMSIS/Device/ST/STM32F4xx/Include 49 | CFLAGS+=-I$(STDP)/Libraries/CMSIS/Include 50 | SOURCE+=$(STDP)/Libraries/CMSIS/Lib/GCC/libarm_cortexM4lf_math.a 51 | 52 | #STemWinLibrary522_4x9i 53 | #CFLAGS+=-I$(STDP)/Libraries/STemWinLibrary522_4x9i/Config 54 | #SOURCE+=$(STDP)/Libraries/STemWinLibrary522_4x9i/Config/*.c 55 | CFLAGS+=-I$(STDP)/Libraries/STemWinLibrary522_4x9i/inc 56 | SOURCE+=$(STDP)/Libraries/STemWinLibrary522_4x9i/Lib/STemWin522_4x9i_CM4_OS_GCC.a 57 | 58 | #STM32F4xx_StdPeriph_Driver 59 | CFLAGS+=-DUSE_STDPERIPH_DRIVER 60 | CFLAGS+=-I$(STDP)/Libraries/STM32F4xx_StdPeriph_Driver/inc 61 | #SOURCE+=$(STDP)/Libraries/STM32F4xx_StdPeriph_Driver/src/*.c <-- compiled separately 62 | 63 | #STM32_USB_Device_Library 64 | #CFLAGS+=-I$(STDP)/Libraries/STM32_USB_Device_Library/Core/inc 65 | #SOURCE+=$(STDP)/Libraries/STM32_USB_Device_Library/Core/src/*.c 66 | #CFLAGS+=-I$(STDP)/Libraries/STM32_USB_Device_Library/Class/audio/inc 67 | #SOURCE+=$(STDP)/Libraries/STM32_USB_Device_Library/Class/audio/src/*.c 68 | #CFLAGS+=-I$(STDP)/Libraries/STM32_USB_Device_Library/Class/cdc/inc 69 | #SOURCE+=$(STDP)/Libraries/STM32_USB_Device_Library/Class/cdc/src/*.c 70 | #CFLAGS+=-I$(STDP)/Libraries/STM32_USB_Device_Library/Class/dfu/inc 71 | #SOURCE+=$(STDP)/Libraries/STM32_USB_Device_Library/Class/dfu/src/*.c 72 | #CFLAGS+=-I$(STDP)/Libraries/STM32_USB_Device_Library/Class/hid/inc 73 | #SOURCE+=$(STDP)/Libraries/STM32_USB_Device_Library/Class/hid/src/*.c 74 | #CFLAGS+=-I$(STDP)/Libraries/STM32_USB_Device_Library/Class/msc/inc 75 | #SOURCE+=$(STDP)/Libraries/STM32_USB_Device_Library/Class/msc/src/*.c 76 | 77 | #STM32_USB_HOST_Library 78 | #CFLAGS+=-I$(STDP)/Libraries/STM32_USB_HOST_Library/Core/inc 79 | #SOURCE+=$(STDP)/Libraries/STM32_USB_HOST_Library/Core/src/*.c 80 | #CFLAGS+=-I$(STDP)/Libraries/STM32_USB_HOST_Library/Class/HID/inc 81 | #SOURCE+=$(STDP)/Libraries/STM32_USB_HOST_Library/Class/HID/src/*.c 82 | #CFLAGS+=-I$(STDP)/Libraries/STM32_USB_HOST_Library/Class/MSC/inc 83 | #SOURCE+=$(STDP)/Libraries/STM32_USB_HOST_Library/Class/MSC/src/*.c 84 | 85 | #STM32_USB_OTG_Driver 86 | #CFLAGS+=-I$(STDP)/Libraries/STM32_USB_OTG_Driver/inc 87 | #SOURCE+=$(STDP)/Libraries/STM32_USB_OTG_Driver/src/*.c 88 | 89 | #Common Utilities 90 | #CFLAGS+=-I$(STDP)/Utilities/Common 91 | #SOURCE+=$(STDP)/Utilities/Common/*.c 92 | 93 | #STM32F429I-Discovery Utilities 94 | CFLAGS+=-I$(STDP)/Utilities/STM32F429I-Discovery 95 | SOURCE+=$(STDP)/Utilities/STM32F429I-Discovery/stm32f429i_discovery.c 96 | #SOURCE+=$(STDP)/Utilities/STM32F429I-Discovery/stm32f429i_discovery_i2c_ee.c 97 | #SOURCE+=$(STDP)/Utilities/STM32F429I-Discovery/stm32f429i_discovery_ioe.c 98 | SOURCE+=$(STDP)/Utilities/STM32F429I-Discovery/stm32f429i_discovery_l3gd20.c 99 | SOURCE+=$(STDP)/Utilities/STM32F429I-Discovery/stm32f429i_discovery_lcd.c 100 | SOURCE+=$(STDP)/Utilities/STM32F429I-Discovery/stm32f429i_discovery_sdram.c 101 | 102 | #Third_Party Utilities 103 | #CFLAGS+=-I$(STDP)/Utilities/Third_Party/fat_fs/inc 104 | #SOURCE+=$(STDP)/Utilities/Third_Party/fat_fs/src/*.c 105 | #SOURCE+=$(STDP)/Utilities/Third_Party/fat_fs/src/option/*.c 106 | 107 | 108 | all: libSTM32F4xx_StdPeriph_Driver.a $(BIN_IMAGE) 109 | 110 | $(BIN_IMAGE): $(EXECUTABLE) 111 | $(OBJCOPY) -O binary $^ $@ 112 | $(OBJCOPY) -O ihex $^ $(HEX_IMAGE) 113 | arm-none-eabi-objdump -h -S -D $(EXECUTABLE) > $(PROJECT).lst 114 | arm-none-eabi-size $(EXECUTABLE) 115 | 116 | $(EXECUTABLE): $(SOURCE) 117 | $(CC) $(CFLAGS) $^ -o $@ libSTM32F4xx_StdPeriph_Driver.a $(LIBS) 118 | 119 | libSTM32F4xx_StdPeriph_Driver.a: 120 | $(CC) $(CFLAGS) -c -D"assert_param(expr)=((void)0)" $(STDP)/Libraries/STM32F4xx_StdPeriph_Driver/src/*.c 121 | @$(AR) cr $@ *.o 122 | rm -rf *.o 123 | 124 | clean: 125 | rm -rf $(EXECUTABLE) 126 | rm -rf $(BIN_IMAGE) 127 | rm -rf $(HEX_IMAGE) 128 | rm -rf *.{lst,a} 129 | 130 | flash: 131 | st-flash write $(BIN_IMAGE) 0x8000000 132 | 133 | .PHONY: clean 134 | -------------------------------------------------------------------------------- /examples/stm32f429-discovery/main.c: -------------------------------------------------------------------------------- 1 | #include "stm32f4xx.h" 2 | #include "arm_math.h" 3 | #include "stm32f429i_discovery.h" 4 | #include "stm32f429i_discovery_lcd.h" 5 | #include "stm32f429i_discovery_l3gd20.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | static char* itoa(int value, char* result, int base); 12 | 13 | // vertex format 14 | typedef struct 15 | { 16 | uint16_t x, y, z; 17 | uint8_t nx, ny, nz; 18 | uint8_t u, v; 19 | } vertex_t; 20 | 21 | // meshes: 22 | #include "teapot.h" 23 | #include "box.h" 24 | #include "pony.h" 25 | // textures: 26 | #include "nyan.h" 27 | #include "box_texture.h" 28 | #include "twilight.h" 29 | 30 | static const r3d_drawcall_t meshes[] = 31 | { 32 | { R3D_PRIMITIVE_TYPE_TRIANGLES, vertices0, sizeof(vertex_t), sizeof(vertices0) / sizeof(vertex_t), 0 }, 33 | { R3D_PRIMITIVE_TYPE_TRIANGLES, vertices1, sizeof(vertex_t), sizeof(vertices1) / sizeof(vertex_t), 0 }, 34 | { R3D_PRIMITIVE_TYPE_TRIANGLES, vertices2, sizeof(vertex_t), sizeof(vertices2) / sizeof(vertex_t), 0 }, 35 | }; 36 | static const r3d_primitive_winding_t windings[] = 37 | { 38 | R3D_PRIMITIVE_WINDING_CW, 39 | R3D_PRIMITIVE_WINDING_CCW, 40 | R3D_PRIMITIVE_WINDING_CCW 41 | }; 42 | static const r3d_texture_t *textures[] = 43 | { 44 | (r3d_texture_t*)&nyan, 45 | (r3d_texture_t*)&box_texture, 46 | (r3d_texture_t*)&twilight 47 | }; 48 | 49 | // simulation stuff 50 | static float time = 0.0f, frametime = 0.0f; 51 | static uint32_t fps = 0; 52 | static uint8_t fps_str[8] = "? FPS"; 53 | static uint8_t info_str[16]; 54 | static mat4_t model, view, projection, mv, mvp; 55 | static int mesh = 0; 56 | static float axes[3] = {0}; 57 | 58 | // shader 59 | typedef struct 60 | { 61 | vec3_t position; 62 | vec3_t normal; 63 | vec2_t uv; 64 | } vs_to_fs_t; 65 | 66 | static void vertex_shader(const vertex_t *in, vs_to_fs_t *out) 67 | { 68 | // decode vertex 69 | const vec3_t pc = { 0.5f, 0.5f, 0.5f }, nc = { 1.0f, 1.0f, 1.0f }; 70 | const float pi = 1.0f / 65535.0f, ni = 2.0f / 255.0f, uvi = 1.0f / 255.0f; 71 | vec3_t position = vec3_sub(vec3_mul(vec3(in->x, in->y, in->z), pi), pc); 72 | vec3_t normal = vec3_sub(vec3_mul(vec3(in->nx, in->ny, in->nz), ni), nc); 73 | vec2_t uv = vec2_mul(vec2(in->u, in->v), uvi); 74 | // transform vertex 75 | out->position = mat4_transform_position(mvp, position); 76 | out->normal = mat4_transform_vector(mv, normal); 77 | out->uv = uv; 78 | } 79 | 80 | static vec4_t fragment_shader(const vs_to_fs_t *in) 81 | { 82 | const vec3_t E = { 0, 0, 1 }; 83 | const vec3_t L = { -0.577350269f, 0.577350269f, 0.577350269f }; 84 | vec3_t N = vec3_normalize(in->normal); 85 | vec3_t H = vec3_normalize(vec3_add(E, L)); 86 | 87 | const float ambient = 0.05f; 88 | float diffuse = vec3_dot(N, L) * 0.6f; 89 | float specular = vec3_dot(N, H); 90 | specular *= specular; specular *= specular; specular *= specular; 91 | specular *= specular; specular *= specular; specular *= specular * 0.6f; 92 | 93 | vec3_t c = r3d_texture_nearest(textures[mesh], in->uv); // read texel 94 | return vec4(ambient + diffuse * c.r + specular, 95 | ambient + diffuse * c.g + specular, 96 | ambient + diffuse * c.b + specular, 1.0f); 97 | } 98 | 99 | static r3d_shader_t shader = 100 | { 101 | (r3d_vertexshader_func)vertex_shader, 102 | (r3d_fragmentshader_func)fragment_shader, 103 | sizeof(vs_to_fs_t) / sizeof(float) 104 | }; 105 | 106 | static void init(void) 107 | { 108 | STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); 109 | 110 | r3dfb_init(); 111 | LCD_SetColors(0x0000, 0xffff); 112 | LCD_SetFont(&Font8x8); 113 | 114 | itoa(meshes[mesh].count / 3, info_str, 10); 115 | strcat(info_str, " tris"); 116 | 117 | r3d_viewport(1, 1, R3DFB_PIXEL_WIDTH - 1, R3DFB_PIXEL_HEIGHT - 1); 118 | r3d_backface_culling = R3D_ENABLE; 119 | r3d_primitive_winding = windings[mesh]; 120 | 121 | projection = mat4_perspective(60.0f, (float)R3DFB_PIXEL_WIDTH / (float)R3DFB_PIXEL_HEIGHT, 0.5f, 5.0f); 122 | view = mat4_lookat(vec3(0.0f, 0.25f, 1.5f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f)); 123 | 124 | L3GD20_InitTypeDef L3GD20_InitStructure; 125 | L3GD20_InitStructure.Power_Mode = L3GD20_MODE_ACTIVE; 126 | L3GD20_InitStructure.Output_DataRate = L3GD20_OUTPUT_DATARATE_1; 127 | L3GD20_InitStructure.Axes_Enable = L3GD20_AXES_ENABLE; 128 | L3GD20_InitStructure.Band_Width = L3GD20_BANDWIDTH_4; 129 | L3GD20_InitStructure.BlockData_Update = L3GD20_BlockDataUpdate_Continous; 130 | L3GD20_InitStructure.Endianness = L3GD20_BLE_LSB; 131 | L3GD20_InitStructure.Full_Scale = L3GD20_FULLSCALE_250; 132 | L3GD20_Init(&L3GD20_InitStructure); 133 | 134 | L3GD20_FilterConfigTypeDef L3GD20_FilterStructure; 135 | L3GD20_FilterStructure.HighPassFilter_Mode_Selection = L3GD20_HPM_NORMAL_MODE_RES; 136 | L3GD20_FilterStructure.HighPassFilter_CutOff_Frequency = L3GD20_HPFCF_0; 137 | L3GD20_FilterConfig(&L3GD20_FilterStructure); 138 | L3GD20_FilterCmd(L3GD20_HIGHPASSFILTER_ENABLE); 139 | } 140 | 141 | static void update(void) 142 | { 143 | uint8_t tmp[6] = {0}; 144 | int16_t a[3] = {0}; 145 | uint8_t tmpreg = 0; 146 | 147 | L3GD20_Read(&tmpreg, L3GD20_CTRL_REG4_ADDR, 1); 148 | L3GD20_Read(tmp, L3GD20_OUT_X_L_ADDR, 6); 149 | 150 | /* check in the control register 4 the data alignment (Big Endian or Little Endian)*/ 151 | if(!(tmpreg & 0x40)) 152 | { 153 | for(int i = 0; i < 3; i++) 154 | a[i] = (int16_t)(((uint16_t)tmp[2 * i + 1] << 8) | (uint16_t)tmp[2 * i]); 155 | } 156 | else 157 | { 158 | for(int i = 0; i < 3; i++) 159 | a[i] = (int16_t)(((uint16_t)tmp[2 * i] << 8) | (uint16_t)tmp[2 * i + 1]); 160 | } 161 | 162 | if(STM_EVAL_PBGetState(BUTTON_USER)) 163 | { 164 | mesh = (mesh + 1) % 3; // next mesh 165 | r3d_primitive_winding = windings[mesh]; 166 | itoa(meshes[mesh].count / 3, info_str, 10); 167 | strcat(info_str, " tris"); 168 | while(STM_EVAL_PBGetState(BUTTON_USER)); // debounce 169 | } 170 | 171 | float delta = frametime - time; 172 | frametime = time; // make frametime a consistent time value during the frames 173 | for(int i = 0; i < 3; i++) 174 | axes[i] += (float)a[i] * delta / 114.285f; 175 | if(axes[0] < 0) axes[0] = 0; 176 | if(axes[0] > 180) axes[0] = 180; 177 | model = mat4_mul( 178 | mat4_rotation(axes[0], vec3(1.0f, 0.0f, 0.0f)), 179 | mat4_rotation(axes[1], vec3(0.0f, 1.0f, 0.0f))); 180 | if(mesh == 1) model = mat4_mul(model, mat4_scaling(vec3(0.5f, 0.5f, 0.5f))); 181 | mv = mat4_mul(view, model); 182 | mvp = mat4_mul(projection, mv); 183 | } 184 | 185 | static void render(void) 186 | { 187 | r3dfb_clear(); 188 | 189 | r3d_shader = shader; 190 | r3d_draw(&meshes[mesh]); 191 | 192 | LCD_DisplayStringLine(LCD_LINE_1, info_str); 193 | LCD_DisplayStringLine(LCD_LINE_3, fps_str); 194 | 195 | char str[16] = "X: "; 196 | itoa(axes[0], str + 3, 10); 197 | LCD_DisplayStringLine(LCD_LINE_5, str); 198 | str[0] = 'Y'; 199 | itoa(axes[1], str + 3, 10); 200 | LCD_DisplayStringLine(LCD_LINE_6, str); 201 | str[0] = 'Z'; 202 | itoa(axes[2], str + 3, 10); 203 | LCD_DisplayStringLine(LCD_LINE_7, str); 204 | 205 | r3dfb_swap_buffers(); 206 | fps++; 207 | } 208 | 209 | int main(void) 210 | { 211 | SysTick_Config(SystemCoreClock / 100); // SysTick event each 10ms 212 | init(); 213 | 214 | while (1) 215 | { 216 | update(); 217 | render(); 218 | } 219 | } 220 | 221 | static char* itoa(int value, char* result, int base) 222 | { 223 | if (base < 2 || base > 36) { *result = '\0'; return result; } 224 | char* ptr = result, *ptr1 = result, tmp_char; 225 | int tmp_value; 226 | 227 | do{ 228 | tmp_value = value; 229 | value /= base; 230 | *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)]; 231 | } while ( value ); 232 | 233 | if (tmp_value < 0) *ptr++ = '-'; 234 | *ptr-- = '\0'; 235 | while(ptr1 < ptr) 236 | { 237 | tmp_char = *ptr; 238 | *ptr--= *ptr1; 239 | *ptr1++ = tmp_char; 240 | } 241 | return result; 242 | } 243 | 244 | uint32_t fps_countdown = 100; 245 | void OnSysTick(void) 246 | { 247 | if(--fps_countdown == 0) 248 | { 249 | itoa(fps, fps_str, 10); 250 | strcat(fps_str, " FPS"); 251 | fps = 0; 252 | fps_countdown = 100; 253 | } 254 | time += 0.01f; 255 | } 256 | 257 | uint32_t L3GD20_TIMEOUT_UserCallback(void) 258 | { 259 | return 0; 260 | } 261 | 262 | #ifdef USE_FULL_ASSERT 263 | void assert_failed(uint8_t* file, uint32_t line) 264 | { 265 | /* printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 266 | while (1) { } 267 | } 268 | #endif 269 | -------------------------------------------------------------------------------- /examples/stm32f429-discovery/startup_stm32f429_439xx.S: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file startup_stm32f429_439xx.s 4 | * @author MCD Application Team 5 | * @version V1.3.0 6 | * @date 08-November-2013 7 | * @brief STM32F429xx/439xx Devices vector table for RIDE7 toolchain. 8 | * This module performs: 9 | * - Set the initial SP 10 | * - Set the initial PC == Reset_Handler, 11 | * - Set the vector table entries with the exceptions ISR address 12 | * - Configure the clock system and the external SRAM mounted on 13 | * STM324x9I-EVAL board to be used as data memory (optional, 14 | * to be enabled by user) 15 | * - Branches to main in the C library (which eventually 16 | * calls main()). 17 | * After Reset the Cortex-M4 processor is in Thread mode, 18 | * priority is Privileged, and the Stack is set to Main. 19 | ****************************************************************************** 20 | * @attention 21 | * 22 | *

© COPYRIGHT 2013 STMicroelectronics

23 | * 24 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 25 | * You may not use this file except in compliance with the License. 26 | * You may obtain a copy of the License at: 27 | * 28 | * http://www.st.com/software_license_agreement_liberty_v2 29 | * 30 | * Unless required by applicable law or agreed to in writing, software 31 | * distributed under the License is distributed on an "AS IS" BASIS, 32 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 33 | * See the License for the specific language governing permissions and 34 | * limitations under the License. 35 | * 36 | ****************************************************************************** 37 | */ 38 | 39 | .syntax unified 40 | /*.cpu cortex-m3 41 | .fpu softvfp*/ 42 | .thumb 43 | 44 | .global g_pfnVectors 45 | .global Default_Handler 46 | 47 | /* start address for the initialization values of the .data section. 48 | defined in linker script */ 49 | .word _sidata 50 | /* start address for the .data section. defined in linker script */ 51 | .word _sdata 52 | /* end address for the .data section. defined in linker script */ 53 | .word _edata 54 | /* start address for the .bss section. defined in linker script */ 55 | .word _sbss 56 | /* end address for the .bss section. defined in linker script */ 57 | .word _ebss 58 | /* stack used for SystemInit_ExtMemCtl; always internal RAM used */ 59 | 60 | /** 61 | * @brief This is the code that gets called when the processor first 62 | * starts execution following a reset event. Only the absolutely 63 | * necessary set is performed, after which the application 64 | * supplied main() routine is called. 65 | * @param None 66 | * @retval : None 67 | */ 68 | 69 | .section .text.Reset_Handler 70 | .weak Reset_Handler 71 | .type Reset_Handler, %function 72 | Reset_Handler: 73 | 74 | /* Copy the data segment initializers from flash to SRAM */ 75 | movs r1, #0 76 | b LoopCopyDataInit 77 | 78 | CopyDataInit: 79 | ldr r3, =_sidata 80 | ldr r3, [r3, r1] 81 | str r3, [r0, r1] 82 | adds r1, r1, #4 83 | 84 | LoopCopyDataInit: 85 | ldr r0, =_sdata 86 | ldr r3, =_edata 87 | adds r2, r0, r1 88 | cmp r2, r3 89 | bcc CopyDataInit 90 | ldr r2, =_sbss 91 | b LoopFillZerobss 92 | /* Zero fill the bss segment. */ 93 | FillZerobss: 94 | movs r3, #0 95 | str r3, [r2], #4 96 | 97 | LoopFillZerobss: 98 | ldr r3, = _ebss 99 | cmp r2, r3 100 | bcc FillZerobss 101 | 102 | /* Call the clock system intitialization function.*/ 103 | bl SystemInit 104 | /* Call the application's entry point.*/ 105 | bl main 106 | bx lr 107 | .size Reset_Handler, .-Reset_Handler 108 | 109 | /** 110 | * @brief This is the code that gets called when the processor receives an 111 | * unexpected interrupt. This simply enters an infinite loop, preserving 112 | * the system state for examination by a debugger. 113 | * @param None 114 | * @retval None 115 | */ 116 | .section .text.Default_Handler,"ax",%progbits 117 | Default_Handler: 118 | Infinite_Loop: 119 | b Infinite_Loop 120 | .size Default_Handler, .-Default_Handler 121 | /****************************************************************************** 122 | * 123 | * The minimal vector table for a Cortex M3. Note that the proper constructs 124 | * must be placed on this to ensure that it ends up at physical address 125 | * 0x0000.0000. 126 | * 127 | *******************************************************************************/ 128 | .section .isr_vector,"a",%progbits 129 | .type g_pfnVectors, %object 130 | .size g_pfnVectors, .-g_pfnVectors 131 | 132 | 133 | g_pfnVectors: 134 | .word _estack 135 | .word Reset_Handler 136 | .word NMI_Handler 137 | .word HardFault_Handler 138 | .word MemManage_Handler 139 | .word BusFault_Handler 140 | .word UsageFault_Handler 141 | .word 0 142 | .word 0 143 | .word 0 144 | .word 0 145 | .word SVC_Handler 146 | .word DebugMon_Handler 147 | .word 0 148 | .word PendSV_Handler 149 | .word SysTick_Handler 150 | 151 | /* External Interrupts */ 152 | .word WWDG_IRQHandler /* Window WatchDog */ 153 | .word PVD_IRQHandler /* PVD through EXTI Line detection */ 154 | .word TAMP_STAMP_IRQHandler /* Tamper and TimeStamps through the EXTI line */ 155 | .word RTC_WKUP_IRQHandler /* RTC Wakeup through the EXTI line */ 156 | .word FLASH_IRQHandler /* FLASH */ 157 | .word RCC_IRQHandler /* RCC */ 158 | .word EXTI0_IRQHandler /* EXTI Line0 */ 159 | .word EXTI1_IRQHandler /* EXTI Line1 */ 160 | .word EXTI2_IRQHandler /* EXTI Line2 */ 161 | .word EXTI3_IRQHandler /* EXTI Line3 */ 162 | .word EXTI4_IRQHandler /* EXTI Line4 */ 163 | .word DMA1_Stream0_IRQHandler /* DMA1 Stream 0 */ 164 | .word DMA1_Stream1_IRQHandler /* DMA1 Stream 1 */ 165 | .word DMA1_Stream2_IRQHandler /* DMA1 Stream 2 */ 166 | .word DMA1_Stream3_IRQHandler /* DMA1 Stream 3 */ 167 | .word DMA1_Stream4_IRQHandler /* DMA1 Stream 4 */ 168 | .word DMA1_Stream5_IRQHandler /* DMA1 Stream 5 */ 169 | .word DMA1_Stream6_IRQHandler /* DMA1 Stream 6 */ 170 | .word ADC_IRQHandler /* ADC1, ADC2 and ADC3s */ 171 | .word CAN1_TX_IRQHandler /* CAN1 TX */ 172 | .word CAN1_RX0_IRQHandler /* CAN1 RX0 */ 173 | .word CAN1_RX1_IRQHandler /* CAN1 RX1 */ 174 | .word CAN1_SCE_IRQHandler /* CAN1 SCE */ 175 | .word EXTI9_5_IRQHandler /* External Line[9:5]s */ 176 | .word TIM1_BRK_TIM9_IRQHandler /* TIM1 Break and TIM9 */ 177 | .word TIM1_UP_TIM10_IRQHandler /* TIM1 Update and TIM10 */ 178 | .word TIM1_TRG_COM_TIM11_IRQHandler /* TIM1 Trigger and Commutation and TIM11 */ 179 | .word TIM1_CC_IRQHandler /* TIM1 Capture Compare */ 180 | .word TIM2_IRQHandler /* TIM2 */ 181 | .word TIM3_IRQHandler /* TIM3 */ 182 | .word TIM4_IRQHandler /* TIM4 */ 183 | .word I2C1_EV_IRQHandler /* I2C1 Event */ 184 | .word I2C1_ER_IRQHandler /* I2C1 Error */ 185 | .word I2C2_EV_IRQHandler /* I2C2 Event */ 186 | .word I2C2_ER_IRQHandler /* I2C2 Error */ 187 | .word SPI1_IRQHandler /* SPI1 */ 188 | .word SPI2_IRQHandler /* SPI2 */ 189 | .word USART1_IRQHandler /* USART1 */ 190 | .word USART2_IRQHandler /* USART2 */ 191 | .word USART3_IRQHandler /* USART3 */ 192 | .word EXTI15_10_IRQHandler /* External Line[15:10]s */ 193 | .word RTC_Alarm_IRQHandler /* RTC Alarm (A and B) through EXTI Line */ 194 | .word OTG_FS_WKUP_IRQHandler /* USB OTG FS Wakeup through EXTI line */ 195 | .word TIM8_BRK_TIM12_IRQHandler /* TIM8 Break and TIM12 */ 196 | .word TIM8_UP_TIM13_IRQHandler /* TIM8 Update and TIM13 */ 197 | .word TIM8_TRG_COM_TIM14_IRQHandler /* TIM8 Trigger and Commutation and TIM14 */ 198 | .word TIM8_CC_IRQHandler /* TIM8 Capture Compare */ 199 | .word DMA1_Stream7_IRQHandler /* DMA1 Stream7 */ 200 | .word FSMC_IRQHandler /* FSMC */ 201 | .word SDIO_IRQHandler /* SDIO */ 202 | .word TIM5_IRQHandler /* TIM5 */ 203 | .word SPI3_IRQHandler /* SPI3 */ 204 | .word UART4_IRQHandler /* UART4 */ 205 | .word UART5_IRQHandler /* UART5 */ 206 | .word TIM6_DAC_IRQHandler /* TIM6 and DAC1&2 underrun errors */ 207 | .word TIM7_IRQHandler /* TIM7 */ 208 | .word DMA2_Stream0_IRQHandler /* DMA2 Stream 0 */ 209 | .word DMA2_Stream1_IRQHandler /* DMA2 Stream 1 */ 210 | .word DMA2_Stream2_IRQHandler /* DMA2 Stream 2 */ 211 | .word DMA2_Stream3_IRQHandler /* DMA2 Stream 3 */ 212 | .word DMA2_Stream4_IRQHandler /* DMA2 Stream 4 */ 213 | .word ETH_IRQHandler /* Ethernet */ 214 | .word ETH_WKUP_IRQHandler /* Ethernet Wakeup through EXTI line */ 215 | .word CAN2_TX_IRQHandler /* CAN2 TX */ 216 | .word CAN2_RX0_IRQHandler /* CAN2 RX0 */ 217 | .word CAN2_RX1_IRQHandler /* CAN2 RX1 */ 218 | .word CAN2_SCE_IRQHandler /* CAN2 SCE */ 219 | .word OTG_FS_IRQHandler /* USB OTG FS */ 220 | .word DMA2_Stream5_IRQHandler /* DMA2 Stream 5 */ 221 | .word DMA2_Stream6_IRQHandler /* DMA2 Stream 6 */ 222 | .word DMA2_Stream7_IRQHandler /* DMA2 Stream 7 */ 223 | .word USART6_IRQHandler /* USART6 */ 224 | .word I2C3_EV_IRQHandler /* I2C3 event */ 225 | .word I2C3_ER_IRQHandler /* I2C3 error */ 226 | .word OTG_HS_EP1_OUT_IRQHandler /* USB OTG HS End Point 1 Out */ 227 | .word OTG_HS_EP1_IN_IRQHandler /* USB OTG HS End Point 1 In */ 228 | .word OTG_HS_WKUP_IRQHandler /* USB OTG HS Wakeup through EXTI */ 229 | .word OTG_HS_IRQHandler /* USB OTG HS */ 230 | .word DCMI_IRQHandler /* DCMI */ 231 | .word CRYP_IRQHandler /* CRYP crypto */ 232 | .word HASH_RNG_IRQHandler /* Hash and Rng */ 233 | .word FPU_IRQHandler /* FPU */ 234 | .word UART7_IRQHandler /* UART7 */ 235 | .word UART8_IRQHandler /* UART8 */ 236 | .word SPI4_IRQHandler /* SPI4 */ 237 | .word SPI5_IRQHandler /* SPI5 */ 238 | .word SPI6_IRQHandler /* SPI6 */ 239 | .word SAI1_IRQHandler /* SAI1 */ 240 | .word LTDC_IRQHandler /* LTDC */ 241 | .word LTDC_ER_IRQHandler /* LTDC error */ 242 | .word DMA2D_IRQHandler /* DMA2D */ 243 | 244 | /******************************************************************************* 245 | * 246 | * Provide weak aliases for each Exception handler to the Default_Handler. 247 | * As they are weak aliases, any function with the same name will override 248 | * this definition. 249 | * 250 | *******************************************************************************/ 251 | .weak NMI_Handler 252 | .thumb_set NMI_Handler,Default_Handler 253 | 254 | .weak HardFault_Handler 255 | .thumb_set HardFault_Handler,Default_Handler 256 | 257 | .weak MemManage_Handler 258 | .thumb_set MemManage_Handler,Default_Handler 259 | 260 | .weak BusFault_Handler 261 | .thumb_set BusFault_Handler,Default_Handler 262 | 263 | .weak UsageFault_Handler 264 | .thumb_set UsageFault_Handler,Default_Handler 265 | 266 | .weak SVC_Handler 267 | .thumb_set SVC_Handler,Default_Handler 268 | 269 | .weak DebugMon_Handler 270 | .thumb_set DebugMon_Handler,Default_Handler 271 | 272 | .weak PendSV_Handler 273 | .thumb_set PendSV_Handler,Default_Handler 274 | 275 | .weak SysTick_Handler 276 | .thumb_set SysTick_Handler,Default_Handler 277 | 278 | .weak WWDG_IRQHandler 279 | .thumb_set WWDG_IRQHandler,Default_Handler 280 | 281 | .weak PVD_IRQHandler 282 | .thumb_set PVD_IRQHandler,Default_Handler 283 | 284 | .weak TAMP_STAMP_IRQHandler 285 | .thumb_set TAMP_STAMP_IRQHandler,Default_Handler 286 | 287 | .weak RTC_WKUP_IRQHandler 288 | .thumb_set RTC_WKUP_IRQHandler,Default_Handler 289 | 290 | .weak FLASH_IRQHandler 291 | .thumb_set FLASH_IRQHandler,Default_Handler 292 | 293 | .weak RCC_IRQHandler 294 | .thumb_set RCC_IRQHandler,Default_Handler 295 | 296 | .weak EXTI0_IRQHandler 297 | .thumb_set EXTI0_IRQHandler,Default_Handler 298 | 299 | .weak EXTI1_IRQHandler 300 | .thumb_set EXTI1_IRQHandler,Default_Handler 301 | 302 | .weak EXTI2_IRQHandler 303 | .thumb_set EXTI2_IRQHandler,Default_Handler 304 | 305 | .weak EXTI3_IRQHandler 306 | .thumb_set EXTI3_IRQHandler,Default_Handler 307 | 308 | .weak EXTI4_IRQHandler 309 | .thumb_set EXTI4_IRQHandler,Default_Handler 310 | 311 | .weak DMA1_Stream0_IRQHandler 312 | .thumb_set DMA1_Stream0_IRQHandler,Default_Handler 313 | 314 | .weak DMA1_Stream1_IRQHandler 315 | .thumb_set DMA1_Stream1_IRQHandler,Default_Handler 316 | 317 | .weak DMA1_Stream2_IRQHandler 318 | .thumb_set DMA1_Stream2_IRQHandler,Default_Handler 319 | 320 | .weak DMA1_Stream3_IRQHandler 321 | .thumb_set DMA1_Stream3_IRQHandler,Default_Handler 322 | 323 | .weak DMA1_Stream4_IRQHandler 324 | .thumb_set DMA1_Stream4_IRQHandler,Default_Handler 325 | 326 | .weak DMA1_Stream5_IRQHandler 327 | .thumb_set DMA1_Stream5_IRQHandler,Default_Handler 328 | 329 | .weak DMA1_Stream6_IRQHandler 330 | .thumb_set DMA1_Stream6_IRQHandler,Default_Handler 331 | 332 | .weak ADC_IRQHandler 333 | .thumb_set ADC_IRQHandler,Default_Handler 334 | 335 | .weak CAN1_TX_IRQHandler 336 | .thumb_set CAN1_TX_IRQHandler,Default_Handler 337 | 338 | .weak CAN1_RX0_IRQHandler 339 | .thumb_set CAN1_RX0_IRQHandler,Default_Handler 340 | 341 | .weak CAN1_RX1_IRQHandler 342 | .thumb_set CAN1_RX1_IRQHandler,Default_Handler 343 | 344 | .weak CAN1_SCE_IRQHandler 345 | .thumb_set CAN1_SCE_IRQHandler,Default_Handler 346 | 347 | .weak EXTI9_5_IRQHandler 348 | .thumb_set EXTI9_5_IRQHandler,Default_Handler 349 | 350 | .weak TIM1_BRK_TIM9_IRQHandler 351 | .thumb_set TIM1_BRK_TIM9_IRQHandler,Default_Handler 352 | 353 | .weak TIM1_UP_TIM10_IRQHandler 354 | .thumb_set TIM1_UP_TIM10_IRQHandler,Default_Handler 355 | 356 | .weak TIM1_TRG_COM_TIM11_IRQHandler 357 | .thumb_set TIM1_TRG_COM_TIM11_IRQHandler,Default_Handler 358 | 359 | .weak TIM1_CC_IRQHandler 360 | .thumb_set TIM1_CC_IRQHandler,Default_Handler 361 | 362 | .weak TIM2_IRQHandler 363 | .thumb_set TIM2_IRQHandler,Default_Handler 364 | 365 | .weak TIM3_IRQHandler 366 | .thumb_set TIM3_IRQHandler,Default_Handler 367 | 368 | .weak TIM4_IRQHandler 369 | .thumb_set TIM4_IRQHandler,Default_Handler 370 | 371 | .weak I2C1_EV_IRQHandler 372 | .thumb_set I2C1_EV_IRQHandler,Default_Handler 373 | 374 | .weak I2C1_ER_IRQHandler 375 | .thumb_set I2C1_ER_IRQHandler,Default_Handler 376 | 377 | .weak I2C2_EV_IRQHandler 378 | .thumb_set I2C2_EV_IRQHandler,Default_Handler 379 | 380 | .weak I2C2_ER_IRQHandler 381 | .thumb_set I2C2_ER_IRQHandler,Default_Handler 382 | 383 | .weak SPI1_IRQHandler 384 | .thumb_set SPI1_IRQHandler,Default_Handler 385 | 386 | .weak SPI2_IRQHandler 387 | .thumb_set SPI2_IRQHandler,Default_Handler 388 | 389 | .weak USART1_IRQHandler 390 | .thumb_set USART1_IRQHandler,Default_Handler 391 | 392 | .weak USART2_IRQHandler 393 | .thumb_set USART2_IRQHandler,Default_Handler 394 | 395 | .weak USART3_IRQHandler 396 | .thumb_set USART3_IRQHandler,Default_Handler 397 | 398 | .weak EXTI15_10_IRQHandler 399 | .thumb_set EXTI15_10_IRQHandler,Default_Handler 400 | 401 | .weak RTC_Alarm_IRQHandler 402 | .thumb_set RTC_Alarm_IRQHandler,Default_Handler 403 | 404 | .weak OTG_FS_WKUP_IRQHandler 405 | .thumb_set OTG_FS_WKUP_IRQHandler,Default_Handler 406 | 407 | .weak TIM8_BRK_TIM12_IRQHandler 408 | .thumb_set TIM8_BRK_TIM12_IRQHandler,Default_Handler 409 | 410 | .weak TIM8_UP_TIM13_IRQHandler 411 | .thumb_set TIM8_UP_TIM13_IRQHandler,Default_Handler 412 | 413 | .weak TIM8_TRG_COM_TIM14_IRQHandler 414 | .thumb_set TIM8_TRG_COM_TIM14_IRQHandler,Default_Handler 415 | 416 | .weak TIM8_CC_IRQHandler 417 | .thumb_set TIM8_CC_IRQHandler,Default_Handler 418 | 419 | .weak DMA1_Stream7_IRQHandler 420 | .thumb_set DMA1_Stream7_IRQHandler,Default_Handler 421 | 422 | .weak FSMC_IRQHandler 423 | .thumb_set FSMC_IRQHandler,Default_Handler 424 | 425 | .weak SDIO_IRQHandler 426 | .thumb_set SDIO_IRQHandler,Default_Handler 427 | 428 | .weak TIM5_IRQHandler 429 | .thumb_set TIM5_IRQHandler,Default_Handler 430 | 431 | .weak SPI3_IRQHandler 432 | .thumb_set SPI3_IRQHandler,Default_Handler 433 | 434 | .weak UART4_IRQHandler 435 | .thumb_set UART4_IRQHandler,Default_Handler 436 | 437 | .weak UART5_IRQHandler 438 | .thumb_set UART5_IRQHandler,Default_Handler 439 | 440 | .weak TIM6_DAC_IRQHandler 441 | .thumb_set TIM6_DAC_IRQHandler,Default_Handler 442 | 443 | .weak TIM7_IRQHandler 444 | .thumb_set TIM7_IRQHandler,Default_Handler 445 | 446 | .weak DMA2_Stream0_IRQHandler 447 | .thumb_set DMA2_Stream0_IRQHandler,Default_Handler 448 | 449 | .weak DMA2_Stream1_IRQHandler 450 | .thumb_set DMA2_Stream1_IRQHandler,Default_Handler 451 | 452 | .weak DMA2_Stream2_IRQHandler 453 | .thumb_set DMA2_Stream2_IRQHandler,Default_Handler 454 | 455 | .weak DMA2_Stream3_IRQHandler 456 | .thumb_set DMA2_Stream3_IRQHandler,Default_Handler 457 | 458 | .weak DMA2_Stream4_IRQHandler 459 | .thumb_set DMA2_Stream4_IRQHandler,Default_Handler 460 | 461 | .weak ETH_IRQHandler 462 | .thumb_set ETH_IRQHandler,Default_Handler 463 | 464 | .weak ETH_WKUP_IRQHandler 465 | .thumb_set ETH_WKUP_IRQHandler,Default_Handler 466 | 467 | .weak CAN2_TX_IRQHandler 468 | .thumb_set CAN2_TX_IRQHandler,Default_Handler 469 | 470 | .weak CAN2_RX0_IRQHandler 471 | .thumb_set CAN2_RX0_IRQHandler,Default_Handler 472 | 473 | .weak CAN2_RX1_IRQHandler 474 | .thumb_set CAN2_RX1_IRQHandler,Default_Handler 475 | 476 | .weak CAN2_SCE_IRQHandler 477 | .thumb_set CAN2_SCE_IRQHandler,Default_Handler 478 | 479 | .weak OTG_FS_IRQHandler 480 | .thumb_set OTG_FS_IRQHandler,Default_Handler 481 | 482 | .weak DMA2_Stream5_IRQHandler 483 | .thumb_set DMA2_Stream5_IRQHandler,Default_Handler 484 | 485 | .weak DMA2_Stream6_IRQHandler 486 | .thumb_set DMA2_Stream6_IRQHandler,Default_Handler 487 | 488 | .weak DMA2_Stream7_IRQHandler 489 | .thumb_set DMA2_Stream7_IRQHandler,Default_Handler 490 | 491 | .weak USART6_IRQHandler 492 | .thumb_set USART6_IRQHandler,Default_Handler 493 | 494 | .weak I2C3_EV_IRQHandler 495 | .thumb_set I2C3_EV_IRQHandler,Default_Handler 496 | 497 | .weak I2C3_ER_IRQHandler 498 | .thumb_set I2C3_ER_IRQHandler,Default_Handler 499 | 500 | .weak OTG_HS_EP1_OUT_IRQHandler 501 | .thumb_set OTG_HS_EP1_OUT_IRQHandler,Default_Handler 502 | 503 | .weak OTG_HS_EP1_IN_IRQHandler 504 | .thumb_set OTG_HS_EP1_IN_IRQHandler,Default_Handler 505 | 506 | .weak OTG_HS_WKUP_IRQHandler 507 | .thumb_set OTG_HS_WKUP_IRQHandler,Default_Handler 508 | 509 | .weak OTG_HS_IRQHandler 510 | .thumb_set OTG_HS_IRQHandler,Default_Handler 511 | 512 | .weak DCMI_IRQHandler 513 | .thumb_set DCMI_IRQHandler,Default_Handler 514 | 515 | .weak CRYP_IRQHandler 516 | .thumb_set CRYP_IRQHandler,Default_Handler 517 | 518 | .weak HASH_RNG_IRQHandler 519 | .thumb_set HASH_RNG_IRQHandler,Default_Handler 520 | 521 | .weak FPU_IRQHandler 522 | .thumb_set FPU_IRQHandler,Default_Handler 523 | 524 | .weak UART7_IRQHandler 525 | .thumb_set UART7_IRQHandler,Default_Handler 526 | 527 | .weak UART8_IRQHandler 528 | .thumb_set UART8_IRQHandler,Default_Handler 529 | 530 | .weak SPI4_IRQHandler 531 | .thumb_set SPI4_IRQHandler,Default_Handler 532 | 533 | .weak SPI5_IRQHandler 534 | .thumb_set SPI5_IRQHandler,Default_Handler 535 | 536 | .weak SPI6_IRQHandler 537 | .thumb_set SPI6_IRQHandler,Default_Handler 538 | 539 | .weak SAI1_IRQHandler 540 | .thumb_set SAI1_IRQHandler,Default_Handler 541 | 542 | .weak LTDC_IRQHandler 543 | .thumb_set LTDC_IRQHandler,Default_Handler 544 | 545 | .weak LTDC_ER_IRQHandler 546 | .thumb_set LTDC_ER_IRQHandler,Default_Handler 547 | 548 | .weak DMA2D_IRQHandler 549 | .thumb_set DMA2D_IRQHandler,Default_Handler 550 | 551 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 552 | -------------------------------------------------------------------------------- /examples/stm32f429-discovery/stm32f429zi_flash.ld: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ands/libr3d/d421d44757e14b8120086a6b1912bc6bea0f6998/examples/stm32f429-discovery/stm32f429zi_flash.ld -------------------------------------------------------------------------------- /examples/stm32f429-discovery/stm32f4xx_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Touch_Panel/stm32f4xx_conf.h 4 | * @author MCD Application Team 5 | * @version V1.0.1 6 | * @date 11-November-2013 7 | * @brief Library configuration file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM32F4xx_CONF_H 30 | #define __STM32F4xx_CONF_H 31 | 32 | #if defined (HSE_VALUE) 33 | /* Redefine the HSE value; it's equal to 8 MHz on the STM32F429I-DISCO Kit */ 34 | #undef HSE_VALUE 35 | #define HSE_VALUE ((uint32_t)8000000) 36 | #endif /* HSE_VALUE */ 37 | 38 | /* Includes ------------------------------------------------------------------*/ 39 | /* Uncomment the line below to enable peripheral header file inclusion */ 40 | #include "stm32f4xx_adc.h" 41 | #include "stm32f4xx_can.h" 42 | #include "stm32f4xx_crc.h" 43 | #include "stm32f4xx_cryp.h" 44 | #include "stm32f4xx_dac.h" 45 | #include "stm32f4xx_dbgmcu.h" 46 | #include "stm32f4xx_dcmi.h" 47 | #include "stm32f4xx_dma.h" 48 | #include "stm32f4xx_exti.h" 49 | #include "stm32f4xx_flash.h" 50 | #include "stm32f4xx_ltdc.h" 51 | #include "stm32f4xx_dma2d.h" 52 | #include "stm32f4xx_fmc.h" 53 | #include "stm32f4xx_hash.h" 54 | #include "stm32f4xx_gpio.h" 55 | #include "stm32f4xx_i2c.h" 56 | #include "stm32f4xx_iwdg.h" 57 | #include "stm32f4xx_pwr.h" 58 | #include "stm32f4xx_rcc.h" 59 | #include "stm32f4xx_rng.h" 60 | #include "stm32f4xx_rtc.h" 61 | #include "stm32f4xx_sdio.h" 62 | #include "stm32f4xx_spi.h" 63 | #include "stm32f4xx_syscfg.h" 64 | #include "stm32f4xx_tim.h" 65 | #include "stm32f4xx_usart.h" 66 | #include "stm32f4xx_wwdg.h" 67 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 68 | 69 | /* Exported types ------------------------------------------------------------*/ 70 | /* Exported constants --------------------------------------------------------*/ 71 | 72 | /* If an external clock source is used, then the value of the following define 73 | should be set to the value of the external clock source, else, if no external 74 | clock is used, keep this define commented */ 75 | /*#define I2S_EXTERNAL_CLOCK_VAL 12288000 */ /* Value of the external clock in Hz */ 76 | 77 | 78 | /* Uncomment the line below to expanse the "assert_param" macro in the 79 | Standard Peripheral Library drivers code */ 80 | /* #define USE_FULL_ASSERT 1 */ 81 | 82 | /* Exported macro ------------------------------------------------------------*/ 83 | #ifdef USE_FULL_ASSERT 84 | 85 | /** 86 | * @brief The assert_param macro is used for function's parameters check. 87 | * @param expr: If expr is false, it calls assert_failed function 88 | * which reports the name of the source file and the source 89 | * line number of the call that failed. 90 | * If expr is true, it returns no value. 91 | * @retval None 92 | */ 93 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 94 | /* Exported functions ------------------------------------------------------- */ 95 | void assert_failed(uint8_t* file, uint32_t line); 96 | #else 97 | #define assert_param(expr) ((void)0) 98 | #endif /* USE_FULL_ASSERT */ 99 | 100 | #endif /* __STM32F4xx_CONF_H */ 101 | 102 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 103 | -------------------------------------------------------------------------------- /examples/stm32f429-discovery/stm32f4xx_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Touch_Panel/stm32f4xx_it.c 4 | * @author MCD Application Team 5 | * @version V1.0.1 6 | * @date 11-November-2013 7 | * @brief Main Interrupt Service Routines. 8 | * This file provides template for all exceptions handler and 9 | * peripherals interrupt service routine. 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | *

© COPYRIGHT 2013 STMicroelectronics

14 | * 15 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 16 | * You may not use this file except in compliance with the License. 17 | * You may obtain a copy of the License at: 18 | * 19 | * http://www.st.com/software_license_agreement_liberty_v2 20 | * 21 | * Unless required by applicable law or agreed to in writing, software 22 | * distributed under the License is distributed on an "AS IS" BASIS, 23 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 | * See the License for the specific language governing permissions and 25 | * limitations under the License. 26 | * 27 | ****************************************************************************** 28 | */ 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_it.h" 32 | 33 | /** @addtogroup STM32F429I_DISCOVERY_Examples 34 | * @{ 35 | */ 36 | 37 | /** @addtogroup Touch_Panel 38 | * @{ 39 | */ 40 | 41 | /* Private typedef -----------------------------------------------------------*/ 42 | /* Private define ------------------------------------------------------------*/ 43 | /* Private macro -------------------------------------------------------------*/ 44 | /* Private variables ---------------------------------------------------------*/ 45 | /* Private function prototypes -----------------------------------------------*/ 46 | /* Private functions ---------------------------------------------------------*/ 47 | 48 | /******************************************************************************/ 49 | /* Cortex-M4 Processor Exceptions Handlers */ 50 | /******************************************************************************/ 51 | 52 | /** 53 | * @brief This function handles NMI exception. 54 | * @param None 55 | * @retval None 56 | */ 57 | void NMI_Handler(void) 58 | { 59 | } 60 | 61 | /** 62 | * @brief This function handles Hard Fault exception. 63 | * @param None 64 | * @retval None 65 | */ 66 | void HardFault_Handler(void) 67 | { 68 | /* Go to infinite loop when Hard Fault exception occurs */ 69 | while (1) 70 | { 71 | } 72 | } 73 | 74 | /** 75 | * @brief This function handles Memory Manage exception. 76 | * @param None 77 | * @retval None 78 | */ 79 | void MemManage_Handler(void) 80 | { 81 | /* Go to infinite loop when Memory Manage exception occurs */ 82 | while (1) 83 | { 84 | } 85 | } 86 | 87 | /** 88 | * @brief This function handles Bus Fault exception. 89 | * @param None 90 | * @retval None 91 | */ 92 | void BusFault_Handler(void) 93 | { 94 | /* Go to infinite loop when Bus Fault exception occurs */ 95 | while (1) 96 | { 97 | } 98 | } 99 | 100 | /** 101 | * @brief This function handles Usage Fault exception. 102 | * @param None 103 | * @retval None 104 | */ 105 | void UsageFault_Handler(void) 106 | { 107 | /* Go to infinite loop when Usage Fault exception occurs */ 108 | while (1) 109 | { 110 | } 111 | } 112 | 113 | /** 114 | * @brief This function handles SVCall exception. 115 | * @param None 116 | * @retval None 117 | */ 118 | void SVC_Handler(void) 119 | { 120 | } 121 | 122 | /** 123 | * @brief This function handles Debug Monitor exception. 124 | * @param None 125 | * @retval None 126 | */ 127 | void DebugMon_Handler(void) 128 | { 129 | } 130 | 131 | /** 132 | * @brief This function handles PendSVC exception. 133 | * @param None 134 | * @retval None 135 | */ 136 | void PendSV_Handler(void) 137 | { 138 | } 139 | 140 | /** 141 | * @brief This function handles SysTick Handler. 142 | * @param None 143 | * @retval None 144 | */ 145 | extern void OnSysTick(void); 146 | void SysTick_Handler(void) 147 | { 148 | OnSysTick(); 149 | } 150 | 151 | void _exit(int code) 152 | { 153 | while(42); 154 | } 155 | 156 | /******************************************************************************/ 157 | /* STM32F4xx Peripherals Interrupt Handlers */ 158 | /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ 159 | /* available peripheral interrupt handler's name please refer to the startup */ 160 | /* file (startup_stm32f429_439xx.s). */ 161 | /******************************************************************************/ 162 | 163 | /** 164 | * @} 165 | */ 166 | 167 | /** 168 | * @} 169 | */ 170 | 171 | 172 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 173 | -------------------------------------------------------------------------------- /examples/stm32f429-discovery/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Touch_Panel/stm32f4xx_it.h 4 | * @author MCD Application Team 5 | * @version V1.0.1 6 | * @date 11-November-2013 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2013 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM32F4xx_IT_H 30 | #define __STM32F4xx_IT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | /* Exported types ------------------------------------------------------------*/ 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* Exported macro ------------------------------------------------------------*/ 40 | /* Exported functions ------------------------------------------------------- */ 41 | 42 | void NMI_Handler(void); 43 | void HardFault_Handler(void); 44 | void MemManage_Handler(void); 45 | void BusFault_Handler(void); 46 | void UsageFault_Handler(void); 47 | void SVC_Handler(void); 48 | void DebugMon_Handler(void); 49 | void PendSV_Handler(void); 50 | void SysTick_Handler(void); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* __STM32F4xx_IT_H */ 57 | 58 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 59 | -------------------------------------------------------------------------------- /examples/stm32f429-discovery/system_stm32f4xx.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.c 4 | * @author MCD Application Team 5 | * @version V1.0.1 6 | * @date 11-November-2013 7 | * @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File. 8 | * This file is customized to run on STM32F429I-DISCO board only. 9 | * 10 | * The STM32F4xx is configured to run at 180 MHz, following the three 11 | * configuration below: 12 | * - PLL_SOURCE_HSI : HSI (~16MHz) used to clock the PLL, and 13 | * the PLL is used as system clock source. 14 | * - PLL_SOURCE_HSE : HSE (8MHz) used to clock the PLL, and 15 | * the PLL is used as system clock source. 16 | * - PLL_SOURCE_HSE_BYPASS(default): HSE bypassed with an external clock 17 | * (8MHz, coming from ST-Link) used to clock 18 | * the PLL, and the PLL is used as system 19 | * clock source. 20 | * 21 | * 1. This file provides two functions and one global variable to be called from 22 | * user application: 23 | * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier 24 | * and Divider factors, AHB/APBx prescalers and Flash settings), 25 | * depending on the configuration made in the clock xls tool. 26 | * This function is called at startup just after reset and 27 | * before branch to main program. This call is made inside 28 | * the "startup_stm32f429_439xx.s" file. 29 | * 30 | * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used 31 | * by the user application to setup the SysTick 32 | * timer or configure other parameters. 33 | * 34 | * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must 35 | * be called whenever the core clock is changed 36 | * during program execution. 37 | * 38 | * 2. After each device reset the HSI (16 MHz) is used as system clock source. 39 | * Then SystemInit() function is called, in "startup_stm32f429_439xx.s" file, to 40 | * configure the system clock before to branch to main program. 41 | * 42 | * 3. If the system clock source selected by user fails to startup, the SystemInit() 43 | * function will do nothing and HSI still used as system clock source. User can 44 | * add some code to deal with this issue inside the SetSysClock() function. 45 | * 46 | * 4. The default value of HSE crystal is set to 8MHz, refer to "HSE_VALUE" define 47 | * in "stm32f4xx.h" file. When HSE is used as system clock source, directly or 48 | * through PLL, and you are using different crystal you have to adapt the HSE 49 | * value to your own configuration. 50 | ****************************************************************************** 51 | * @attention 52 | * 53 | *

© COPYRIGHT 2013 STMicroelectronics

54 | * 55 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 56 | * You may not use this file except in compliance with the License. 57 | * You may obtain a copy of the License at: 58 | * 59 | * http://www.st.com/software_license_agreement_liberty_v2 60 | * 61 | * Unless required by applicable law or agreed to in writing, software 62 | * distributed under the License is distributed on an "AS IS" BASIS, 63 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 64 | * See the License for the specific language governing permissions and 65 | * limitations under the License. 66 | * 67 | ****************************************************************************** 68 | */ 69 | 70 | /** @addtogroup CMSIS 71 | * @{ 72 | */ 73 | 74 | /** @addtogroup stm32f4xx_system 75 | * @{ 76 | */ 77 | 78 | /** @addtogroup STM32F4xx_System_Private_Includes 79 | * @{ 80 | */ 81 | 82 | #include "stm32f4xx.h" 83 | 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @addtogroup STM32F4xx_System_Private_TypesDefinitions 89 | * @{ 90 | */ 91 | 92 | /** 93 | * @} 94 | */ 95 | 96 | /** @addtogroup STM32F4xx_System_Private_Defines 97 | * @{ 98 | */ 99 | 100 | /************************* Miscellaneous Configuration ************************/ 101 | /*!< Uncomment the following line if you need to use external SDRAM mounted 102 | on STM32F429I-DISCO board as data memory */ 103 | /* #define DATA_IN_ExtSDRAM */ 104 | 105 | /*!< Uncomment the following line if you need to relocate your vector Table in 106 | Internal SRAM. */ 107 | /* #define VECT_TAB_SRAM */ 108 | #define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. 109 | This value must be a multiple of 0x200. */ 110 | /******************************************************************************/ 111 | 112 | /************************* PLL Parameters *************************************/ 113 | /* Select the PLL clock source */ 114 | 115 | //#define PLL_SOURCE_HSI // HSI (~16 MHz) used to clock the PLL, and the PLL is used as system clock source 116 | #define PLL_SOURCE_HSE // HSE (8MHz) used to clock the PLL, and the PLL is used as system clock source 117 | //#define PLL_SOURCE_HSE_BYPASS // HSE bypassed with an external clock (8MHz, coming from ST-Link) used to clock 118 | // the PLL, and the PLL is used as system clock source 119 | 120 | 121 | /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */ 122 | #if defined (PLL_SOURCE_HSI) 123 | #define PLL_M 16 124 | #else 125 | #define PLL_M 8 126 | #endif 127 | #define PLL_N 360 128 | 129 | /* SYSCLK = PLL_VCO / PLL_P */ 130 | #define PLL_P 2 131 | 132 | /* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */ 133 | #define PLL_Q 7 134 | 135 | /******************************************************************************/ 136 | 137 | 138 | 139 | /** 140 | * @} 141 | */ 142 | 143 | /** @addtogroup STM32F4xx_System_Private_Macros 144 | * @{ 145 | */ 146 | 147 | /** 148 | * @} 149 | */ 150 | 151 | /** @addtogroup STM32F4xx_System_Private_Variables 152 | * @{ 153 | */ 154 | 155 | uint32_t SystemCoreClock = 180000000; 156 | 157 | __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; 158 | 159 | /** 160 | * @} 161 | */ 162 | 163 | /** @addtogroup STM32F4xx_System_Private_FunctionPrototypes 164 | * @{ 165 | */ 166 | 167 | static void SetSysClock(void); 168 | #if defined (DATA_IN_ExtSDRAM) 169 | static void SystemInit_ExtMemCtl(void); 170 | #endif /* DATA_IN_ExtSDRAM */ 171 | 172 | /** 173 | * @} 174 | */ 175 | 176 | /** @addtogroup STM32F4xx_System_Private_Functions 177 | * @{ 178 | */ 179 | 180 | /** 181 | * @brief Setup the microcontroller system 182 | * Initialize the Embedded Flash Interface, the PLL and update the 183 | * SystemFrequency variable. 184 | * @param None 185 | * @retval None 186 | */ 187 | void SystemInit(void) 188 | { 189 | /* FPU settings ------------------------------------------------------------*/ 190 | #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) 191 | SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */ 192 | #endif 193 | /* Reset the RCC clock configuration to the default reset state ------------*/ 194 | /* Set HSION bit */ 195 | RCC->CR |= (uint32_t)0x00000001; 196 | 197 | /* Reset CFGR register */ 198 | RCC->CFGR = 0x00000000; 199 | 200 | /* Reset HSEON, CSSON and PLLON bits */ 201 | RCC->CR &= (uint32_t)0xFEF6FFFF; 202 | 203 | /* Reset PLLCFGR register */ 204 | RCC->PLLCFGR = 0x24003010; 205 | 206 | /* Reset HSEBYP bit */ 207 | RCC->CR &= (uint32_t)0xFFFBFFFF; 208 | 209 | /* Disable all interrupts */ 210 | RCC->CIR = 0x00000000; 211 | 212 | #if defined (DATA_IN_ExtSDRAM) 213 | SystemInit_ExtMemCtl(); 214 | #endif /* DATA_IN_ExtSDRAM */ 215 | 216 | /* Configure the System clock source, PLL Multiplier and Divider factors, 217 | AHB/APBx prescalers and Flash settings ----------------------------------*/ 218 | SetSysClock(); 219 | 220 | /* Configure the Vector Table location add offset address ------------------*/ 221 | #ifdef VECT_TAB_SRAM 222 | SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ 223 | #else 224 | SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */ 225 | #endif 226 | } 227 | 228 | /** 229 | * @brief Update SystemCoreClock variable according to Clock Register Values. 230 | * The SystemCoreClock variable contains the core clock (HCLK), it can 231 | * be used by the user application to setup the SysTick timer or configure 232 | * other parameters. 233 | * 234 | * @note Each time the core clock (HCLK) changes, this function must be called 235 | * to update SystemCoreClock variable value. Otherwise, any configuration 236 | * based on this variable will be incorrect. 237 | * 238 | * @note - The system frequency computed by this function is not the real 239 | * frequency in the chip. It is calculated based on the predefined 240 | * constant and the selected clock source: 241 | * 242 | * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) 243 | * 244 | * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) 245 | * 246 | * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) 247 | * or HSI_VALUE(*) multiplied/divided by the PLL factors. 248 | * 249 | * (*) HSI_VALUE is a constant defined in stm32f4xx.h file (default value 250 | * 16 MHz) but the real value may vary depending on the variations 251 | * in voltage and temperature. 252 | * 253 | * (**) HSE_VALUE is a constant defined in stm32f4xx.h file (default value 254 | * 8 MHz), user has to ensure that HSE_VALUE is same as the real 255 | * frequency of the crystal used. Otherwise, this function may 256 | * have wrong result. 257 | * 258 | * - The result of this function could be not correct when using fractional 259 | * value for HSE crystal. 260 | * 261 | * @param None 262 | * @retval None 263 | */ 264 | void SystemCoreClockUpdate(void) 265 | { 266 | uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2; 267 | 268 | /* Get SYSCLK source -------------------------------------------------------*/ 269 | tmp = RCC->CFGR & RCC_CFGR_SWS; 270 | 271 | switch (tmp) 272 | { 273 | case 0x00: /* HSI used as system clock source */ 274 | SystemCoreClock = HSI_VALUE; 275 | break; 276 | case 0x04: /* HSE used as system clock source */ 277 | SystemCoreClock = HSE_VALUE; 278 | break; 279 | case 0x08: /* PLL used as system clock source */ 280 | 281 | /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N 282 | SYSCLK = PLL_VCO / PLL_P 283 | */ 284 | pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22; 285 | pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM; 286 | 287 | if (pllsource != 0) 288 | { 289 | /* HSE used as PLL clock source */ 290 | pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6); 291 | } 292 | else 293 | { 294 | /* HSI used as PLL clock source */ 295 | pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6); 296 | } 297 | 298 | pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2; 299 | SystemCoreClock = pllvco/pllp; 300 | break; 301 | default: 302 | SystemCoreClock = HSI_VALUE; 303 | break; 304 | } 305 | /* Compute HCLK frequency --------------------------------------------------*/ 306 | /* Get HCLK prescaler */ 307 | tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; 308 | /* HCLK frequency */ 309 | SystemCoreClock >>= tmp; 310 | } 311 | 312 | /** 313 | * @brief Configures the System clock source, PLL Multiplier and Divider factors, 314 | * AHB/APBx prescalers and Flash settings 315 | * @Note This function should be called only once the RCC clock configuration 316 | * is reset to the default reset state (done in SystemInit() function). 317 | * @param None 318 | * @retval None 319 | */ 320 | static void SetSysClock(void) 321 | { 322 | /******************************************************************************/ 323 | /* PLL (clocked by HSE) used as System clock source */ 324 | /******************************************************************************/ 325 | __IO uint32_t StartUpCounter = 0, HSEStatus = 0; 326 | 327 | 328 | #ifdef PLL_SOURCE_HSI 329 | 330 | /* Configure the main PLL */ 331 | RCC->PLLCFGR = PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) | 332 | (RCC_PLLCFGR_PLLSRC_HSI) | (PLL_Q << 24); 333 | 334 | #else /* PLL_SOURCE_HSE_BYPASS or PLL_SOURCE_HSE */ 335 | 336 | /* Enable HSE */ 337 | RCC->CR |= ((uint32_t)RCC_CR_HSEON); 338 | #ifdef PLL_SOURCE_HSE_BYPASS 339 | /* Enable HSE */ 340 | RCC->CR |= ((uint32_t)RCC_CR_HSEBYP); 341 | #endif /* PLL_SOURCE_HSE_BYPASS */ 342 | /* Wait till HSE is ready and if Time out is reached exit */ 343 | do 344 | { 345 | HSEStatus = RCC->CR & RCC_CR_HSERDY; 346 | StartUpCounter++; 347 | } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); 348 | 349 | if ((RCC->CR & RCC_CR_HSERDY) != RESET) 350 | { 351 | HSEStatus = (uint32_t)0x01; 352 | } 353 | else 354 | { 355 | HSEStatus = (uint32_t)0x00; 356 | } 357 | 358 | if (HSEStatus == (uint32_t)0x01) 359 | { 360 | /* Configure the main PLL */ 361 | RCC->PLLCFGR = PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) | 362 | (RCC_PLLCFGR_PLLSRC_HSE) | (PLL_Q << 24); 363 | 364 | } 365 | else 366 | { /* If HSE fails to start-up, the application will have wrong clock 367 | configuration. User can add here some code to deal with this error */ 368 | } 369 | #endif /*PLL_SOURCE_HSI*/ 370 | 371 | /* Select regulator voltage output Scale 1 mode, System frequency up to 180 MHz */ 372 | RCC->APB1ENR |= RCC_APB1ENR_PWREN; 373 | PWR->CR |= PWR_CR_VOS; 374 | 375 | /* HCLK = SYSCLK / 1*/ 376 | RCC->CFGR |= RCC_CFGR_HPRE_DIV1; 377 | 378 | /* PCLK2 = HCLK / 2*/ 379 | RCC->CFGR |= RCC_CFGR_PPRE2_DIV2; 380 | 381 | /* PCLK1 = HCLK / 4*/ 382 | RCC->CFGR |= RCC_CFGR_PPRE1_DIV4; 383 | 384 | /* Enable the main PLL */ 385 | RCC->CR |= RCC_CR_PLLON; 386 | 387 | /* Wait till the main PLL is ready */ 388 | while((RCC->CR & RCC_CR_PLLRDY) == 0) 389 | { 390 | } 391 | 392 | /* Enable the Over-drive to extend the clock frequency to 180 Mhz */ 393 | PWR->CR |= PWR_CR_ODEN; 394 | while((PWR->CSR & PWR_CSR_ODRDY) == 0) 395 | { 396 | } 397 | PWR->CR |= PWR_CR_ODSWEN; 398 | while((PWR->CSR & PWR_CSR_ODSWRDY) == 0) 399 | { 400 | } 401 | 402 | /* Configure Flash prefetch, Instruction cache, Data cache and wait state */ 403 | FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS; 404 | 405 | /* Select the main PLL as system clock source */ 406 | RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); 407 | RCC->CFGR |= RCC_CFGR_SW_PLL; 408 | 409 | /* Wait till the main PLL is used as system clock source */ 410 | while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL); 411 | { 412 | } 413 | } 414 | 415 | #ifdef DATA_IN_ExtSDRAM 416 | /** 417 | * @brief Setup the external memory controller. 418 | * Called in startup_stm32f429_439xx.s before jump to main. 419 | * This function configures the external SDRAM mounted on STM32F429I DISCO board 420 | * This SDRAM will be used as program data memory (including heap and stack). 421 | * @param None 422 | * @retval None 423 | */ 424 | void SystemInit_ExtMemCtl(void) 425 | { 426 | register uint32_t tmpreg = 0, timeout = 0xFFFF; 427 | register uint32_t index; 428 | 429 | /* Enable GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH and GPIOI interface 430 | clock */ 431 | RCC->AHB1ENR |= 0x000001FC; 432 | 433 | /* Connect PCx pins to FMC Alternate function */ 434 | GPIOC->AFR[0] = 0x0000000c; 435 | GPIOC->AFR[1] = 0x00007700; 436 | /* Configure PCx pins in Alternate function mode */ 437 | GPIOC->MODER = 0x00a00002; 438 | /* Configure PCx pins speed to 50 MHz */ 439 | GPIOC->OSPEEDR = 0x00a00002; 440 | /* Configure PCx pins Output type to push-pull */ 441 | GPIOC->OTYPER = 0x00000000; 442 | /* No pull-up, pull-down for PCx pins */ 443 | GPIOC->PUPDR = 0x00500000; 444 | 445 | /* Connect PDx pins to FMC Alternate function */ 446 | GPIOD->AFR[0] = 0x000000CC; 447 | GPIOD->AFR[1] = 0xCC000CCC; 448 | /* Configure PDx pins in Alternate function mode */ 449 | GPIOD->MODER = 0xA02A000A; 450 | /* Configure PDx pins speed to 50 MHz */ 451 | GPIOD->OSPEEDR = 0xA02A000A; 452 | /* Configure PDx pins Output type to push-pull */ 453 | GPIOD->OTYPER = 0x00000000; 454 | /* No pull-up, pull-down for PDx pins */ 455 | GPIOD->PUPDR = 0x00000000; 456 | 457 | /* Connect PEx pins to FMC Alternate function */ 458 | GPIOE->AFR[0] = 0xC00000CC; 459 | GPIOE->AFR[1] = 0xCCCCCCCC; 460 | /* Configure PEx pins in Alternate function mode */ 461 | GPIOE->MODER = 0xAAAA800A; 462 | /* Configure PEx pins speed to 50 MHz */ 463 | GPIOE->OSPEEDR = 0xAAAA800A; 464 | /* Configure PEx pins Output type to push-pull */ 465 | GPIOE->OTYPER = 0x00000000; 466 | /* No pull-up, pull-down for PEx pins */ 467 | GPIOE->PUPDR = 0x00000000; 468 | 469 | /* Connect PFx pins to FMC Alternate function */ 470 | GPIOF->AFR[0] = 0xcccccccc; 471 | GPIOF->AFR[1] = 0xcccccccc; 472 | /* Configure PFx pins in Alternate function mode */ 473 | GPIOF->MODER = 0xAA800AAA; 474 | /* Configure PFx pins speed to 50 MHz */ 475 | GPIOF->OSPEEDR = 0xAA800AAA; 476 | /* Configure PFx pins Output type to push-pull */ 477 | GPIOF->OTYPER = 0x00000000; 478 | /* No pull-up, pull-down for PFx pins */ 479 | GPIOF->PUPDR = 0x00000000; 480 | 481 | /* Connect PGx pins to FMC Alternate function */ 482 | GPIOG->AFR[0] = 0xcccccccc; 483 | GPIOG->AFR[1] = 0xcccccccc; 484 | /* Configure PGx pins in Alternate function mode */ 485 | GPIOG->MODER = 0xaaaaaaaa; 486 | /* Configure PGx pins speed to 50 MHz */ 487 | GPIOG->OSPEEDR = 0xaaaaaaaa; 488 | /* Configure PGx pins Output type to push-pull */ 489 | GPIOG->OTYPER = 0x00000000; 490 | /* No pull-up, pull-down for PGx pins */ 491 | GPIOG->PUPDR = 0x00000000; 492 | 493 | /* Connect PHx pins to FMC Alternate function */ 494 | GPIOH->AFR[0] = 0x00C0CC00; 495 | GPIOH->AFR[1] = 0xCCCCCCCC; 496 | /* Configure PHx pins in Alternate function mode */ 497 | GPIOH->MODER = 0xAAAA08A0; 498 | /* Configure PHx pins speed to 50 MHz */ 499 | GPIOH->OSPEEDR = 0xAAAA08A0; 500 | /* Configure PHx pins Output type to push-pull */ 501 | GPIOH->OTYPER = 0x00000000; 502 | /* No pull-up, pull-down for PHx pins */ 503 | GPIOH->PUPDR = 0x00000000; 504 | 505 | /* Connect PIx pins to FMC Alternate function */ 506 | GPIOI->AFR[0] = 0xCCCCCCCC; 507 | GPIOI->AFR[1] = 0x00000CC0; 508 | /* Configure PIx pins in Alternate function mode */ 509 | GPIOI->MODER = 0x0028AAAA; 510 | /* Configure PIx pins speed to 50 MHz */ 511 | GPIOI->OSPEEDR = 0x0028AAAA; 512 | /* Configure PIx pins Output type to push-pull */ 513 | GPIOI->OTYPER = 0x00000000; 514 | /* No pull-up, pull-down for PIx pins */ 515 | GPIOI->PUPDR = 0x00000000; 516 | 517 | /*-- FMC Configuration ------------------------------------------------------*/ 518 | /* Enable the FMC interface clock */ 519 | RCC->AHB3ENR |= 0x00000001; 520 | 521 | /* Configure and enable SDRAM bank1 */ 522 | FMC_Bank5_6->SDCR[0] = 0x000029D0; 523 | FMC_Bank5_6->SDTR[0] = 0x01115351; 524 | 525 | /* SDRAM initialization sequence */ 526 | /* Clock enable command */ 527 | FMC_Bank5_6->SDCMR = 0x00000011; 528 | tmpreg = FMC_Bank5_6->SDSR & 0x00000020; 529 | while((tmpreg != 0) && (timeout-- > 0)) 530 | { 531 | tmpreg = FMC_Bank5_6->SDSR & 0x00000020; 532 | } 533 | 534 | /* Delay */ 535 | for (index = 0; index<1000; index++); 536 | 537 | /* PALL command */ 538 | FMC_Bank5_6->SDCMR = 0x00000012; 539 | timeout = 0xFFFF; 540 | while((tmpreg != 0) && (timeout-- > 0)) 541 | { 542 | tmpreg = FMC_Bank5_6->SDSR & 0x00000020; 543 | } 544 | 545 | /* Auto refresh command */ 546 | FMC_Bank5_6->SDCMR = 0x00000073; 547 | timeout = 0xFFFF; 548 | while((tmpreg != 0) && (timeout-- > 0)) 549 | { 550 | tmpreg = FMC_Bank5_6->SDSR & 0x00000020; 551 | } 552 | 553 | /* MRD register program */ 554 | FMC_Bank5_6->SDCMR = 0x00046014; 555 | timeout = 0xFFFF; 556 | while((tmpreg != 0) && (timeout-- > 0)) 557 | { 558 | tmpreg = FMC_Bank5_6->SDSR & 0x00000020; 559 | } 560 | 561 | /* Set refresh count */ 562 | tmpreg = FMC_Bank5_6->SDRTR; 563 | FMC_Bank5_6->SDRTR = (tmpreg | (0x0000027C<<1)); 564 | 565 | /* Disable write protection */ 566 | tmpreg = FMC_Bank5_6->SDCR[0]; 567 | FMC_Bank5_6->SDCR[0] = (tmpreg & 0xFFFFFDFF); 568 | 569 | /* 570 | Bank1_SDRAM is configured as follow: 571 | 572 | FMC_SDRAMTimingInitStructure.FMC_LoadToActiveDelay = 2; 573 | FMC_SDRAMTimingInitStructure.FMC_ExitSelfRefreshDelay = 6; 574 | FMC_SDRAMTimingInitStructure.FMC_SelfRefreshTime = 4; 575 | FMC_SDRAMTimingInitStructure.FMC_RowCycleDelay = 6; 576 | FMC_SDRAMTimingInitStructure.FMC_WriteRecoveryTime = 2; 577 | FMC_SDRAMTimingInitStructure.FMC_RPDelay = 2; 578 | FMC_SDRAMTimingInitStructure.FMC_RCDDelay = 2; 579 | 580 | FMC_SDRAMInitStructure.FMC_Bank = SDRAM_BANK; 581 | FMC_SDRAMInitStructure.FMC_ColumnBitsNumber = FMC_ColumnBits_Number_8b; 582 | FMC_SDRAMInitStructure.FMC_RowBitsNumber = FMC_RowBits_Number_11b; 583 | FMC_SDRAMInitStructure.FMC_SDMemoryDataWidth = FMC_SDMemory_Width_16b; 584 | FMC_SDRAMInitStructure.FMC_InternalBankNumber = FMC_InternalBank_Number_4; 585 | FMC_SDRAMInitStructure.FMC_CASLatency = FMC_CAS_Latency_3; 586 | FMC_SDRAMInitStructure.FMC_WriteProtection = FMC_Write_Protection_Disable; 587 | FMC_SDRAMInitStructure.FMC_SDClockPeriod = FMC_SDClock_Period_2; 588 | FMC_SDRAMInitStructure.FMC_ReadBurst = FMC_Read_Burst_disable; 589 | FMC_SDRAMInitStructure.FMC_ReadPipeDelay = FMC_ReadPipe_Delay_1; 590 | FMC_SDRAMInitStructure.FMC_SDRAMTimingStruct = &FMC_SDRAMTimingInitStructure; 591 | */ 592 | 593 | } 594 | #endif /* DATA_IN_ExtSDRAM */ 595 | 596 | 597 | /** 598 | * @} 599 | */ 600 | 601 | /** 602 | * @} 603 | */ 604 | 605 | /** 606 | * @} 607 | */ 608 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 609 | -------------------------------------------------------------------------------- /examples/textures/nyan.h: -------------------------------------------------------------------------------- 1 | static const struct { uint16_t w, h; uint8_t d[]; } nyan = 2 | { 3 | 64, 64, 4 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 5 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 6 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 7 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 8 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 9 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 10 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 11 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 12 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 13 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 14 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 15 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 16 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 17 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 18 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 19 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 20 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 21 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 22 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 23 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 24 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 25 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 26 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 27 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 28 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 29 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 30 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 31 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 32 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 33 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 34 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 35 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 36 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 37 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 38 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 39 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 40 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 41 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 42 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 43 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 44 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 45 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 46 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 47 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 48 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 49 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 50 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 51 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 52 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 53 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 54 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 55 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 56 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 57 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 58 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 59 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 60 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 61 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 62 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 63 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 64 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 65 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 66 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 67 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 68 | "\377\377\377\377\337\377\377\377\377\377\377\377\377\377\377\377\377\377" 69 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 70 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 71 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 72 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 73 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 74 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 75 | "\377\377\377\377\337\377\377\377\377\377\377\377\377\377\377\377\377\377" 76 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 77 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 78 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 79 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 80 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 81 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 82 | "\377\377\377\377\377\377\337\377\377\377\377\377\377\377\377\377\377\377" 83 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 84 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 85 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 86 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 87 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 88 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 89 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 90 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 91 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 92 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 93 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 94 | "\377\377\377\377\377\377\377\377\337\377\337\377\377\377\377\377\377\377" 95 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 96 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 97 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 98 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 99 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 100 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 101 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 102 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 103 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 104 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 105 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 106 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 107 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 108 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 109 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 110 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 111 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 112 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 113 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 114 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 115 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 116 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 117 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 118 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 119 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 120 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 121 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 122 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 123 | "\377\377\377\377\337\377\337\377\337\377\377\377\377\377\377\377\377\377" 124 | "\377\377\377\377\337\377\377\377\377\377\377\377\377\377\377\377\377\377" 125 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 126 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 127 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 128 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 129 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 130 | "\377\377\377\377\377\377\377\377\377\377\377\377\376\377\377\377\337\377" 131 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 132 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 133 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 134 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 135 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 136 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 137 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 138 | "\377\377\376\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 139 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 140 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 141 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 142 | "\377\377\377\377\377\377\377\377\377\377\377\377\336\377\337\377\377\377" 143 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 144 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 145 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 146 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 147 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 148 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 149 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\337\377" 150 | "\337\377\377\377\377\377\336\377\377\377\377\377\377\377\377\377\377\377" 151 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 152 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 153 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 154 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 155 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 156 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377A\10\0\0\202\10\0" 157 | "\0\0\0\0\0\0\0\0\0\0\0\40\0\40\0\0\0\0\0\0\0\40\0A\10\0\0\40\0\377\377\337" 158 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 159 | "\377\377\377\377\377\377\377\377\377\40\372a\372\202\372@\372\377\377\377" 160 | "\377\377\377\377\377\377\377\377\377\377\377\201\372\40\372A\372\40\372a" 161 | "\372A\372\377\377\377\377\377\377\377\377\377\377\377\377\202\372\40\372" 162 | "b\372A\372A\372\40\372\0\372\40\10\265\376\265\376\265\376\225\376\325\376" 163 | "\325\376\265\376\264\376\265\376\264\376\264\376\265\376\264\376\265\376" 164 | "\325\376\266\376\325\376\326\376@\10\377\377\377\377\377\377\377\377\377" 165 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 166 | "\377@\372\40\372\40\372\40\372b\372\202\372A\372\202\372\202\372A\372A\372" 167 | "\40\372\0\372\40\372\0\372\0\372\0\372a\372\40\372A\372\40\372A\372\202\372" 168 | "\40\372\0\372\0\372\0\372\0\372\0\372\201\20\325\376\264\376\264\376\233" 169 | "\375Z\375z\375\233\375Z\375z\375\232\375\233\375z\375{\375\233\375\233\375" 170 | "z\375\232\375\264\376\224\376\265\376\0\0\377\377\377\377\377\377\377\377" 171 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 172 | "a\372\40\372\40\372A\372\40\372\0\372\0\372\0\372\0\372\40\372\0\372!\372" 173 | "\0\372\40\372a\372!\372\40\372\40\372\40\372\40\372\0\372\0\372\40\372\40" 174 | "\372\0\372\40\372A\372\40\372\40\372\202\10\264\376\264\376\233\375Z\375" 175 | "Z\375Z\375Z\3757\373:\375Z\375Z\375Z\375\366\372:\375Z\375Z\375Z\375\232" 176 | "\375\264\376\264\376\0\0\377\377\377\377\377\377\377\377\377\377\377\377" 177 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377c\375@\375a\375b" 178 | "\375a\372\0\372A\372\40\372\40\372\40\372a\372b\375a\375@\375A\375@\375@" 179 | "\375@\372\40\372!\372\0\372\40\372b\372\202\375@\375@\375@\375@\375`\375" 180 | "\303\40\265\376\272\375Z\375\326\372Z\375Z\375Z\375:\375Z\375Z\375Z\375Z" 181 | "\375:\375:\375Z\375{\375\326\372\32\375Z\375\264\376\0\0\337\377\377\377" 182 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 183 | "\377\377\377\377@\375@\375@\375@\375b\375a\375a\375a\375b\375a\375@\375@" 184 | "\375@\375@\375@\375@\375@\375A\375@\375A\375@\375@\375A\375@\375@\375@\375" 185 | "@\375@\375@\375\202\20\265\376Z\375Z\375:\375:\375Z\375Z\375Z\375Z\375z\375" 186 | "{\375Z\375Z\375\207A\207AY\355Z\375:\375Z\375\264\376\0\0\337\377\337\377" 187 | "\303\30\343\30\336\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 188 | "\377\377\377A\375@\375@\375@\375@\375@\375\40\375\40\375@\375@\375@\375b" 189 | "\375a\375A\375@\375@\375@\375@\375@\375@\375@\375\40\375@\375A\375A\375@" 190 | "\375@\375@\375@\375A\10\325\376Z\375Z\375Z\375Z\375{\375Z\375Z\375:\375\225" 191 | "\372Z\375Z\375\303\30""4\245\24\245\303\30Z\375Z\375z\375\265\376\0\0\376" 192 | "\377e)T\2454\255HJ\337\377\377\377\377\377\377\377\377\377\377\377\377\377" 193 | "\377\377\341\377\343\377\342\377\341\377`\375\40\375@\375@\375@\375@\375" 194 | "a\375\346\377\341\377\345\377\342\377\345\377\347\377A\375@\375@\375@\375" 195 | "@\375\200\375\340\377\340\377\340\377\340\377\341\377\345\377\242\20\265" 196 | "\376Z\375:\375:\375Z\375z\375Z\375:\375Z\375:\375z\375Z\375\243\20""4\245" 197 | "T\245T\255\242\20z\375Z\375\264\376E)\3\31""4\255T\2555\255E)\377\377\377" 198 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\340\377\340\377\342" 199 | "\377\342\377\343\377\342\377\342\377\344\377\347\377\350\377\342\377\341" 200 | "\377\340\377\340\377\340\377\341\377\343\377\342\377\343\377\343\377\344" 201 | "\377\343\377\341\377\340\377B)\3029\343\377\340\377\340\377\0\0\325\376z" 202 | "\375Z\375Z\375Z\375Z\375\225\372z\375Z\375Z\375Z\375Z\375\242\20T\2554\255" 203 | "T\2554\245E)\303\30\303\30\4\31""4\255U\2554\245T\255E)\377\377\377\377\377" 204 | "\377\377\377\377\377\377\377\377\377\377\377\341\377\340\377\340\377\340" 205 | "\377\340\377\340\377\340\377\340\377\340\377\340\377\340\377\343\377\340" 206 | "\377\342\377\346\377\345\377\341\377\340\377\340\377\340\377\340\377\340" 207 | "\377\342\377#)T\2554\255$!\341\377\340\377\40\0\325\376Z\375Z\375Z\375Z\375" 208 | "[\375:\375Z\375Z\375Z\375Z\375Z\375\242\20T\2554\245T\255T\255T\255T\255" 209 | "T\255T\255U\255T\2554\2554\255\303\30\377\377\377\377\377\377\377\377\377" 210 | "\377\377\377\377\377\377\377\353\267\351\257\350\257\353\267\340\377\340" 211 | "\377\342\377\340\377\341\377\341\377\341\377\353\267\353\267\351\257\352" 212 | "\267\350\257\352\267\350\377\341\377\346\377\343\377\340\377\353\377\242" 213 | "\20T\2554\245\242\20\242\20\242\20$!\326\376z\375\325\372:\375Z\375Z\375" 214 | "Z\375Z\375Z\3755\372\371\374%)\363\2344\245T\255T\2454\255T\2555\255T\255" 215 | "T\255T\2554\255U\245U\255T\255\3069\377\377\377\377\377\377\377\377\377\377" 216 | "\377\377\377\377\347\257\347\257\347\257\350\257\352\267\351\257\353\267" 217 | "\351\257\352\267\352\267\354\277\350\257\347\257\347\247\350\257\347\257" 218 | "\347\257\350\257\350\257\353\267\351\257\351\257\352\267\355\277e)U\2554" 219 | "\255T\255T\255f)\325\376[\375:\375:\375Z\375Z\375z\375Z\375Z\375\32\375Z" 220 | "\375\202\20""4\245T\255U\255\337\377$!T\255T\255T\2554\255T\255\377\377\4" 221 | "!4\2454\255\343\30\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 222 | "\352\267\350\257\347\257\347\257\347\257\347\247\347\257\347\257\347\257" 223 | "\347\257\350\257\352\267\347\257\350\257\350\257\350\257\347\257\347\257" 224 | "\347\257\347\257\347\247\347\257\347\257\347\257\350\257\243\30\243\20T\255" 225 | "4\255\302\30\325\376{\375Z\375Z\375Z\375Z\375Z\375Z\375Z\375Z\375:\375\242" 226 | "\20""4\255U\255T\255\242\20\242\20T\255T\255T\255\20514\255\302\30\242\30" 227 | """4\245T\255D)\377\377\377\377\377\377\377\377\377\377\377\377\377\377\177" 228 | "\15\177\25\177\15_\5\350\257\350\257\350\257\350\257\347\257\347\247\347" 229 | "\257\237\35_\5\177\15\177\25_\15\177\25\352\267\351\267\347\257\347\257\351" 230 | "\257\350\257\350\257\3375\277%\237%\344\40\242\20E!\264\376z\375Z\375Z\375" 231 | ":\375Y\3755\372Z\375Z\375Z\375Z\375\243\20T\255\324\373\324\373T\255U\255" 232 | "T\255T\2554\2554\255T\255T\2554\255\324\373\324\373$!\337\377\377\377\377" 233 | "\377\377\377\377\377\377\377\377\377_\5_\5_\5_\5_\15_\15_\15\177\25\177\15" 234 | "\177\25\177\25_\5_\5_\5_\5_\5_\5\177\25\177\25\177\15\177\15\177\15_\5_\5" 235 | "_\5_\5_\5_\15\177\25\242\20\265\376\264\376{\375\225\372:\375Z\375:\375Z" 236 | "\375Z\375Z\375Z\375\242\20T\245\324\373\324\373T\255$!4\245U\255\343\30""4" 237 | "\255T\255(BT\255\364\363\324\373\302\30\377\377\377\377\377\377\377\377\377" 238 | "\377\377\377\377\377_\15_\5_\15_\15_\5_\5_\5?\5_\5_\5\177\15\177\25_\5_\15" 239 | "_\5?\5_\5_\15\177\5?\5?\5_\5_\5_\5\177\15\177\15?\5_\5\177\25\0\0\264\376" 240 | "\264\376\264\376\231\374\32\375Z\375Z\375Z\375Z\375Z\375Z\375[\375$)4\245" 241 | "U\2554\255\303\30\303\30\242\20\242\20\303\30\343\30\303\30\24\255T\255E" 242 | "!\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\277\332" 243 | "?\332?\332\177\322_\5_\15\177\15_\5_\15_\5?\5_\332?\322_\332\237\322\177" 244 | "\332_\332\177\15_\5_\5\177\15_\5_\5\237\25?\332\377\321\377\321_\322\37\322" 245 | "\0\0\302\30\265\376\264\376\225\376u\376\264\376\224\376\264\376\264\376" 246 | "\225\376u\376\225\376\264\376\343\30T\255U\255T\255T\2555\2555\2554\245T" 247 | "\255T\255T\255\242\20\337\377\377\377\377\377\377\377\377\377\377\377\377" 248 | "\377\377\377\377\377?\322\37\322\37\332?\332\237\332\237\332_\332\177\322" 249 | "_\332_\332\177\322\37\322\37\322\37\332?\332?\322\37\332\177\322_\322_\332" 250 | "?\322?\332?\322?\332\377\321?\322\37\322\37\332\0\0\24\245T\255\302\30\0" 251 | "\0\303\20$!\243\20\242\30\242\20@\10\0\0A\10a\10\202\30\303\30\3!\343\30" 252 | "\303\30\303\30\343\40\343\30\3079\3!\302\20\302\30\377\377\377\377\377\377" 253 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377_\332_\322_\322_" 254 | "\322\37\332\37\322\37\322\37\322?\322\37\322?\322?\322_\332?\322?\322?\322" 255 | "?\322?\322\37\332\37\322\37\322?\322?\332?\322_\332?\322?\322\37\322\0\0" 256 | "\24\245T\255\243\20\276\367$!T\255T\255T\255\242\20\377\377\377\377\377\377" 257 | "\377\377\377\377\336\377\243\20T\2454\255\243\30\377\377\302\20""4\2454\255" 258 | "\302\30\377\377\337\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 259 | "\377\377\377\377\377\377\377\377\377\377\377\377\377_\332?\322_\332?\322" 260 | "\237\332\37\322?\332\377\377\377\377\377\377\377\377\377\377\377\377_\332" 261 | "\237\322_\332_\322?\332\37\322?\322\377\377\377\377\377\377\377\377\242\20" 262 | "e)\303\30\377\377\337\377\377\377\343\30a\10\343\30\303\30\377\377\377\377" 263 | "\377\377\377\377\377\377\377\377\377\377\303\30\242\20\343\30\377\377\377" 264 | "\377\242\30\201\20\303\30\377\377\377\377\377\377\377\377\377\377\377\377" 265 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 266 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 267 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 268 | "\377\377\277\377\377\377\377\377\377\377\377\377\377\377\377\377\337\377" 269 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\337\377\377\377" 270 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 271 | "\337\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 272 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 273 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 274 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 275 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 276 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\337\377\377\377" 277 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 278 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 279 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 280 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 281 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 282 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 283 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 284 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 285 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 286 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 287 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 288 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 289 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 290 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 291 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 292 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 293 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 294 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 295 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 296 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 297 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 298 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 299 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 300 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 301 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 302 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 303 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 304 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 305 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 306 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 307 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 308 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 309 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 310 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 311 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 312 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 313 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 314 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 315 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 316 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 317 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 318 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 319 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 320 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 321 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 322 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 323 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 324 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 325 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 326 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 327 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 328 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 329 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 330 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 331 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 332 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 333 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 334 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 335 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 336 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 337 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 338 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 339 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 340 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 341 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 342 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 343 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 344 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 345 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 346 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 347 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 348 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 349 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 350 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 351 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 352 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 353 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 354 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 355 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 356 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 357 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 358 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 359 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 360 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 361 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 362 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 363 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 364 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 365 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 366 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 367 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 368 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 369 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 370 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 371 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 372 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 373 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 374 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 375 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 376 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 377 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 378 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 379 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 380 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 381 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 382 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 383 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 384 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 385 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 386 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 387 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 388 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 389 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 390 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 391 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 392 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 393 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 394 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 395 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 396 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 397 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 398 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 399 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 400 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 401 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 402 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 403 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 404 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 405 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 406 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 407 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 408 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 409 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 410 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 411 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 412 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 413 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 414 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 415 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 416 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 417 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 418 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 419 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 420 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 421 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 422 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 423 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 424 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 425 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 426 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 427 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 428 | "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" 429 | "\377\377" 430 | }; 431 | 432 | -------------------------------------------------------------------------------- /libs/r3d/r3d.c: -------------------------------------------------------------------------------- 1 | /********************************* 2 | * r3d -- 3D rendering library * 3 | * author: Andreas Mantler (ands) * 4 | *********************************/ 5 | 6 | #include 7 | #include 8 | 9 | typedef void (*r3d_primitive_rasterizer_func)(const float *in); 10 | static void r3d_points_rasterizer(const float *in); 11 | static void r3d_lines_rasterizer(const float *in); 12 | static void r3d_line_strip_rasterizer(const float *in); 13 | static void r3d_line_fan_rasterizer(const float *in); 14 | static void r3d_triangles_rasterizer(const float *in); 15 | static void r3d_triangle_strip_rasterizer(const float *in); 16 | static void r3d_triangle_fan_rasterizer(const float *in); 17 | //static void r3d_quads_rasterizer(const float *in); 18 | //static void r3d_quad_strip_rasterizer(const float *in); 19 | 20 | // public variables 21 | r3d_switch_t r3d_backface_culling = R3D_DISABLE; 22 | r3d_primitive_winding_t r3d_primitive_winding = R3D_PRIMITIVE_WINDING_CCW; 23 | r3d_shader_t r3d_shader = {0}; 24 | 25 | // private variables 26 | static vec2_t r3d_viewport_position = {0}; 27 | static vec2_t r3d_viewport_half_size = {0}; 28 | static int r3d_viewport_width = 0; 29 | static int r3d_viewport_height = 0; 30 | static float *r3d_primitive_vertex_buffer; 31 | static uint8_t r3d_primitive_vertex_index = 0; 32 | static r3d_primitive_rasterizer_func r3d_primitive_rasterizers[R3D_PRIMITIVE_TYPE_NUM] = 33 | { 34 | r3d_points_rasterizer, 35 | r3d_lines_rasterizer, 36 | r3d_line_strip_rasterizer, // line_loop: differentiation happens in r3d_draw. 37 | r3d_line_strip_rasterizer, 38 | r3d_line_fan_rasterizer, 39 | r3d_triangles_rasterizer, 40 | r3d_triangle_strip_rasterizer, 41 | r3d_triangle_fan_rasterizer, 42 | //r3d_quads_rasterizer, 43 | //r3d_quad_strip_rasterizer 44 | }; 45 | 46 | void r3d_viewport(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) 47 | { 48 | r3d_viewport_position.x = x0; 49 | r3d_viewport_position.y = y0; 50 | r3d_viewport_half_size.x = (float)(x1 - x0) * 0.5f; 51 | r3d_viewport_half_size.y = (float)(y1 - y0) * 0.5f; 52 | r3d_viewport_width = x1 - x0; 53 | r3d_viewport_height = y1 - y0; 54 | } 55 | 56 | void r3d_draw(const r3d_drawcall_t *drawcall) 57 | { 58 | const void *vs_in; 59 | float vs_out[R3D_VERTEX_ELEMENTS_MAX]; 60 | 61 | // initialize rasterizer 62 | float primitive_buffer[R3D_PRIMITIVE_VERTEX_BUFFER * R3D_VERTEX_ELEMENTS_MAX]; 63 | r3d_primitive_rasterizer_func rasterizer = r3d_primitive_rasterizers[drawcall->primitive_type]; 64 | r3d_primitive_vertex_buffer = primitive_buffer; 65 | r3d_primitive_vertex_index = 0; 66 | 67 | if(drawcall->indices == 0) 68 | { 69 | // rasterize vertex arrays 70 | vs_in = drawcall->vertices; 71 | const void *vs_end = vs_in + drawcall->count * drawcall->stride; 72 | if(drawcall->primitive_type == R3D_PRIMITIVE_TYPE_LINE_LOOP) 73 | { 74 | r3d_shader.vertexshader(vs_end - drawcall->stride, vs_out); 75 | rasterizer(vs_out); 76 | } 77 | while(vs_in != vs_end) 78 | { 79 | r3d_shader.vertexshader(vs_in, vs_out); 80 | rasterizer(vs_out); 81 | vs_in += drawcall->stride; 82 | } 83 | } 84 | else 85 | { 86 | // rasterize indexed arrays 87 | if(drawcall->primitive_type == R3D_PRIMITIVE_TYPE_LINE_LOOP) 88 | { 89 | vs_in = drawcall->vertices + drawcall->indices[drawcall->count - 1] * drawcall->stride; 90 | r3d_shader.vertexshader(vs_in, vs_out); 91 | rasterizer(vs_out); 92 | } 93 | for(uint32_t i = 0; i < drawcall->count; i++) 94 | { 95 | vs_in = drawcall->vertices + drawcall->indices[i] * drawcall->stride; 96 | r3d_shader.vertexshader(vs_in, vs_out); 97 | rasterizer(vs_out); 98 | } 99 | } 100 | } 101 | 102 | // interpolators 103 | static inline void r3d_primitive_linear_interpolate(const float *in0, const float *in1, float *out, float x) 104 | { 105 | float xr = 1.0f - x; 106 | for(int i = 0; i < r3d_shader.vertex_out_elements; i++) 107 | out[i] = in0[i] * xr + in1[i] * x; 108 | } 109 | 110 | static inline void r3d_primitive_barycentric_interpolate(const float *in0, const float *in1, const float *in2, float *out, float t0, float t1, float t2) 111 | { 112 | for(int i = 0; i < r3d_shader.vertex_out_elements; i++) 113 | out[i] = in0[i] * t0 + in1[i] * t1 + in2[i] * t2; 114 | } 115 | 116 | // temporary buffer access 117 | #define r3d_primitive_vertex_buffer(i) (r3d_primitive_vertex_buffer + (i) * r3d_shader.vertex_out_elements) 118 | #define r3d_primitive_vertex_buffer_put(i, in) memcpy(r3d_primitive_vertex_buffer(i), in, r3d_shader.vertex_out_elements * sizeof(float)); 119 | 120 | static inline void r3d_fragment_rasterizer(const float *in, uint16_t x, uint16_t y) 121 | { 122 | // TODO: alpha test 123 | float z = (in[2] - 1.0f) *-0.5f; 124 | if(z > r3d_get_depth(x, y)) 125 | { 126 | vec4_t color = r3d_shader.fragmentshader(in); 127 | color.r = float_clamp(color.r, 0.0f, 1.0f); 128 | color.g = float_clamp(color.g, 0.0f, 1.0f); 129 | color.b = float_clamp(color.b, 0.0f, 1.0f); 130 | r3d_set_pixel(x, y, z, color.rgb); 131 | } 132 | } 133 | 134 | static void r3d_points_rasterizer(const float *in) 135 | { 136 | if(in[0] < -1.0f || in[0] > 1.0f || in[1] < -1.0f || in[1] > 1.0f || in[2] < -1.0f || in[2] > 1.0f) 137 | return; 138 | uint16_t x = (uint16_t)((in[0] + 1.0f) * r3d_viewport_half_size.x + r3d_viewport_position.x); 139 | uint16_t y = (uint16_t)((in[1] - 1.0f) *-r3d_viewport_half_size.y + r3d_viewport_position.y); 140 | r3d_fragment_rasterizer(in, x, y); 141 | } 142 | 143 | static void r3d_line_rasterizer(const float *v0, const float *v1) 144 | { 145 | // bresenham 146 | int x0 = (int)((v0[0] + 1.0f) * r3d_viewport_half_size.x + r3d_viewport_position.x); 147 | int y0 = (int)((v0[1] - 1.0f) *-r3d_viewport_half_size.y + r3d_viewport_position.y); 148 | int x1 = (int)((v1[0] + 1.0f) * r3d_viewport_half_size.x + r3d_viewport_position.x); 149 | int y1 = (int)((v1[1] - 1.0f) *-r3d_viewport_half_size.y + r3d_viewport_position.y); 150 | 151 | int dx = x1 - x0, sx = x0 < x1 ? 1 : -1; 152 | int dy = y1 - y0, sy = y0 < y1 ? 1 : -1; 153 | if(dx < 0) dx = -dx; 154 | if(dy < 0) dy = -dy; 155 | int cur = 0, len = dx < dy ? dy : dx; 156 | int err = (dx > dy ? dx : -dy) / 2, e2; 157 | float t; 158 | float *vi = r3d_primitive_vertex_buffer(1); 159 | 160 | for(;;) 161 | { 162 | t = (float)(cur++) / (float)len; // TODO: incremental? 163 | r3d_primitive_linear_interpolate(v0, v1, vi, t); 164 | r3d_fragment_rasterizer(vi, x0, y0); 165 | 166 | if (x0 == x1 && y0 == y1) break; 167 | e2 = err; 168 | if (e2 >-dx) { err -= dy; x0 += sx; } 169 | if (e2 < dy) { err += dx; y0 += sy; } 170 | } 171 | } 172 | 173 | static void r3d_lines_rasterizer(const float *in) 174 | { 175 | if(r3d_primitive_vertex_index == 1) 176 | { 177 | r3d_line_rasterizer(r3d_primitive_vertex_buffer(0), in); 178 | r3d_primitive_vertex_index = 0; 179 | } 180 | else 181 | { 182 | r3d_primitive_vertex_buffer_put(0, in); 183 | r3d_primitive_vertex_index = 1; 184 | } 185 | } 186 | 187 | static void r3d_line_strip_rasterizer(const float *in) 188 | { 189 | if(r3d_primitive_vertex_index == 1) 190 | { 191 | r3d_line_rasterizer(r3d_primitive_vertex_buffer(0), in); 192 | r3d_primitive_vertex_buffer_put(0, in); 193 | } 194 | else 195 | { 196 | r3d_primitive_vertex_buffer_put(0, in); 197 | r3d_primitive_vertex_index = 1; 198 | } 199 | } 200 | 201 | static void r3d_line_fan_rasterizer(const float *in) 202 | { 203 | if(r3d_primitive_vertex_index == 1) 204 | { 205 | r3d_line_rasterizer(r3d_primitive_vertex_buffer(0), in); 206 | } 207 | else 208 | { 209 | r3d_primitive_vertex_buffer_put(0, in); 210 | r3d_primitive_vertex_index = 1; 211 | } 212 | } 213 | 214 | // screen orientations: cw vs ccw 215 | static inline float r3d_orientation2f(const float *i0, const float *i1, const float *i2) 216 | { 217 | return (i1[0] - i0[0]) * (i2[1] - i0[1]) - (i1[1] - i0[1]) * (i2[0] - i0[0]); 218 | } 219 | 220 | static inline int r3d_orientation2i(const int *i0, const int *i1, const int *i2) 221 | { 222 | return (i1[0] - i0[0]) * (i2[1] - i0[1]) - (i1[1] - i0[1]) * (i2[0] - i0[0]); 223 | } 224 | 225 | // triangle front face rasterizer 226 | static void r3d_triangle_front_rasterizer(const float *v0, const float *v1, const float *v2) 227 | { 228 | int i0[2], i1[2], i2[2]; 229 | i0[0] = (int)((v0[0] + 1.0f) * r3d_viewport_half_size.x + r3d_viewport_position.x); 230 | i0[1] = (int)((v0[1] - 1.0f) *-r3d_viewport_half_size.y + r3d_viewport_position.y); 231 | i1[0] = (int)((v1[0] + 1.0f) * r3d_viewport_half_size.x + r3d_viewport_position.x); 232 | i1[1] = (int)((v1[1] - 1.0f) *-r3d_viewport_half_size.y + r3d_viewport_position.y); 233 | i2[0] = (int)((v2[0] + 1.0f) * r3d_viewport_half_size.x + r3d_viewport_position.x); 234 | i2[1] = (int)((v2[1] - 1.0f) *-r3d_viewport_half_size.y + r3d_viewport_position.y); 235 | 236 | int minX = int_max(int_min(i0[0], int_min(i1[0], i2[0])), (int)r3d_viewport_position.x); // bounding box 237 | int minY = int_max(int_min(i0[1], int_min(i1[1], i2[1])), (int)r3d_viewport_position.y); 238 | int maxX = int_min(int_max(i0[0], int_max(i1[0], i2[0])), (int)r3d_viewport_position.x + r3d_viewport_width - 1); 239 | int maxY = int_min(int_max(i0[1], int_max(i1[1], i2[1])), (int)r3d_viewport_position.y + r3d_viewport_height - 1); 240 | 241 | int A01 = i0[1] - i1[1], B01 = i1[0] - i0[0]; // triangle setup 242 | int A12 = i1[1] - i2[1], B12 = i2[0] - i1[0]; 243 | int A20 = i2[1] - i0[1], B20 = i0[0] - i2[0]; 244 | 245 | int p[2] = { minX, minY }; // barycentric coordinates at minX/minY corner 246 | int w0_row = r3d_orientation2i(i1, i2, p); 247 | int w1_row = r3d_orientation2i(i2, i0, p); 248 | int w2_row = r3d_orientation2i(i0, i1, p); 249 | 250 | float vi[R3D_VERTEX_ELEMENTS_MAX]; // interpolated vertex 251 | 252 | for (p[1] = minY; p[1] <= maxY; p[1]++) 253 | { 254 | int w0 = w0_row; // barycentric coordinates at start of row 255 | int w1 = w1_row; 256 | int w2 = w2_row; 257 | 258 | for (p[0] = minX; p[0] <= maxX; p[0]++) 259 | { 260 | if ((w0 | w1 | w2) >= 0) // if p is on or inside all edges, render pixel. 261 | { 262 | float wai = 1.0f / (float)(w0 + w1 + w2); 263 | r3d_primitive_barycentric_interpolate(v0, v1, v2, vi, w0 * wai, w1 * wai, w2 * wai); 264 | r3d_fragment_rasterizer(vi, p[0], p[1]); 265 | } 266 | w0 += A12; // one step to the right 267 | w1 += A20; 268 | w2 += A01; 269 | } 270 | w0_row += B12; // one row step 271 | w1_row += B20; 272 | w2_row += B01; 273 | } 274 | } 275 | 276 | static void r3d_triangle_rasterizer(const float *v0, const float *v1, const float *v2) 277 | { 278 | if(r3d_primitive_winding == R3D_PRIMITIVE_WINDING_CCW) 279 | { 280 | if(r3d_orientation2f(v0, v1, v2) > 0.0f) 281 | r3d_triangle_front_rasterizer(v0, v2, v1); // ccw front face 282 | else if(!r3d_backface_culling) 283 | r3d_triangle_front_rasterizer(v0, v1, v2); // ccw back face 284 | } 285 | else 286 | { 287 | if(r3d_orientation2f(v0, v1, v2) < 0.0f) 288 | r3d_triangle_front_rasterizer(v0, v1, v2); // cw front face 289 | else if(!r3d_backface_culling) 290 | r3d_triangle_front_rasterizer(v0, v2, v1); // cw back face 291 | } 292 | } 293 | 294 | static void r3d_triangles_rasterizer(const float *in) 295 | { 296 | if(r3d_primitive_vertex_index == 2) 297 | { 298 | r3d_triangle_rasterizer(r3d_primitive_vertex_buffer(0), r3d_primitive_vertex_buffer(1), in); 299 | r3d_primitive_vertex_index = 0; 300 | } 301 | else 302 | { 303 | r3d_primitive_vertex_buffer_put(r3d_primitive_vertex_index, in); 304 | r3d_primitive_vertex_index++; 305 | } 306 | } 307 | 308 | static void r3d_triangle_strip_rasterizer(const float *in) 309 | { 310 | if(r3d_primitive_vertex_index == 2) 311 | { 312 | r3d_triangle_rasterizer(r3d_primitive_vertex_buffer(0), r3d_primitive_vertex_buffer(1), in); 313 | r3d_primitive_vertex_buffer_put(r3d_primitive_vertex_index, in); 314 | r3d_primitive_vertex_index++; 315 | } 316 | else if(r3d_primitive_vertex_index == 3) 317 | { 318 | r3d_triangle_rasterizer(r3d_primitive_vertex_buffer(2), r3d_primitive_vertex_buffer(1), in); 319 | r3d_primitive_vertex_buffer_put(0, r3d_primitive_vertex_buffer(2)); 320 | r3d_primitive_vertex_buffer_put(1, in); 321 | r3d_primitive_vertex_index = 2; 322 | } 323 | else 324 | { 325 | r3d_primitive_vertex_buffer_put(r3d_primitive_vertex_index, in); 326 | r3d_primitive_vertex_index++; 327 | } 328 | } 329 | 330 | static void r3d_triangle_fan_rasterizer(const float *in) 331 | { 332 | if(r3d_primitive_vertex_index == 2) 333 | { 334 | r3d_triangle_rasterizer(r3d_primitive_vertex_buffer(0), r3d_primitive_vertex_buffer(1), in); 335 | r3d_primitive_vertex_buffer_put(1, in); 336 | } 337 | else 338 | { 339 | r3d_primitive_vertex_buffer_put(r3d_primitive_vertex_index, in); 340 | r3d_primitive_vertex_index++; 341 | } 342 | } 343 | 344 | /*static void r3d_quads_rasterizer(const float *in) 345 | { 346 | 347 | } 348 | 349 | static void r3d_quad_strip_rasterizer(const float *in) 350 | { 351 | 352 | }*/ 353 | 354 | 355 | -------------------------------------------------------------------------------- /libs/r3d/r3d.h: -------------------------------------------------------------------------------- 1 | /********************************* 2 | * r3d -- 3D rendering library * 3 | * author: Andreas Mantler (ands) * 4 | *********************************/ 5 | 6 | #ifndef R3D_H 7 | #define R3D_H 8 | 9 | #include 10 | #include 11 | 12 | /*****************************************************************************/ 13 | // to configure by user: 14 | 15 | // number of float elements per vertex passed to/between shaders (at least 3) 16 | #define R3D_VERTEX_ELEMENTS_MAX 16 17 | 18 | // sets the maximum number for *_FAN vertices. 19 | // should be at least: 20 | // 6 if quads are used, ? 21 | // 4 if triangles are used, 22 | // 2 if lines are used or 23 | // 0 if only points are used 24 | #define R3D_PRIMITIVE_VERTEX_BUFFER 4 25 | 26 | // to implement: 27 | void r3d_set_pixel(uint16_t x, uint16_t y, float z, vec3_t color); 28 | float r3d_get_depth(uint16_t x, uint16_t y); 29 | 30 | // end of configuration section 31 | /*****************************************************************************/ 32 | 33 | // types 34 | typedef uint8_t r3d_switch_t; 35 | #define R3D_DISABLE 0 36 | #define R3D_ENABLE 1 37 | 38 | typedef uint8_t r3d_primitive_winding_t; 39 | #define R3D_PRIMITIVE_WINDING_CW 0 40 | #define R3D_PRIMITIVE_WINDING_CCW 1 41 | 42 | typedef uint8_t r3d_primitive_type_t; 43 | #define R3D_PRIMITIVE_TYPE_POINTS 0x00 44 | #define R3D_PRIMITIVE_TYPE_LINES 0x01 45 | #define R3D_PRIMITIVE_TYPE_LINE_LOOP 0x02 46 | #define R3D_PRIMITIVE_TYPE_LINE_STRIP 0x03 47 | #define R3D_PRIMITIVE_TYPE_LINE_FAN 0x04 48 | #define R3D_PRIMITIVE_TYPE_TRIANGLES 0x05 49 | #define R3D_PRIMITIVE_TYPE_TRIANGLE_STRIP 0x06 50 | #define R3D_PRIMITIVE_TYPE_TRIANGLE_FAN 0x07 51 | //#define R3D_PRIMITIVE_TYPE_QUADS 0x08 52 | //#define R3D_PRIMITIVE_TYPE_QUAD_STRIP 0x09 53 | #define R3D_PRIMITIVE_TYPE_NUM 0x08 //0x0a 54 | 55 | typedef void (*r3d_vertexshader_func)(const void *in, float *out); 56 | typedef vec4_t (*r3d_fragmentshader_func)(const float *in); 57 | typedef struct 58 | { 59 | r3d_vertexshader_func vertexshader; 60 | r3d_fragmentshader_func fragmentshader; 61 | uint8_t vertex_out_elements; // number of floats passed from vs to fs 62 | } r3d_shader_t; 63 | 64 | typedef struct 65 | { 66 | r3d_primitive_type_t primitive_type; 67 | const void *vertices; // vertex buffer 68 | uint8_t stride; // vertex stride 69 | uint32_t count; // number of vertices/indices 70 | const uint16_t *indices; // index buffer 71 | } r3d_drawcall_t; 72 | 73 | typedef struct 74 | { 75 | uint16_t width; 76 | uint16_t height; 77 | uint16_t data[]; 78 | } r3d_texture_t; 79 | 80 | // variables 81 | extern r3d_switch_t r3d_backface_culling; 82 | extern r3d_primitive_winding_t r3d_primitive_winding; 83 | extern r3d_shader_t r3d_shader; 84 | 85 | // functions 86 | void r3d_viewport(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); 87 | void r3d_draw(const r3d_drawcall_t *drawcall); 88 | 89 | // texturing (inlined for speed) 90 | static inline vec3_t r3d_texture_nearest(const r3d_texture_t *texture, vec2_t uv) 91 | { 92 | int ui = (int)uv.x; 93 | int vi = (int)uv.y; 94 | if(uv.x < 0) ui--; 95 | if(uv.y < 0) vi--; 96 | uv.x -= ui; 97 | uv.y -= vi; 98 | uv.x *= texture->width - 1; 99 | uv.y *= texture->height - 1; 100 | ui = uv.x; 101 | vi = uv.y; 102 | uint16_t c = texture->data[vi * texture->width + ui]; 103 | const float ri = 1.0f / 63488.0f, gi = 1.0f / 2016.0f, bi = 1.0f / 31.0f; 104 | return vec3((c & 63488) * ri, (c & 2016) * gi, (c & 31) * bi); 105 | } 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /libs/r3d/r3d_math.h: -------------------------------------------------------------------------------- 1 | /********************************* 2 | * r3d -- 3D rendering library * 3 | * author: Andreas Mantler (ands) * 4 | *********************************/ 5 | 6 | #ifndef R3D_MATH_H 7 | #define R3D_MATH_H 8 | 9 | #if defined (ARM_MATH_CM4) || (ARM_MATH_CM3) || (ARM_MATH_CM0) 10 | #define R3D_ARM_MATH 11 | #include "arm_math.h" 12 | #else 13 | #include 14 | #endif 15 | 16 | #define float_pi 3.1415926535897932f 17 | #define float_pi_over180 0.017453293f 18 | 19 | typedef struct 20 | { 21 | union 22 | { 23 | float v[2]; 24 | struct { float x, y; }; 25 | struct { float r, g; }; 26 | }; 27 | } vec2_t; 28 | 29 | typedef struct 30 | { 31 | union 32 | { 33 | float v[3]; 34 | struct { float x, y, z; }; 35 | struct { float r, g, b; }; 36 | vec2_t xy; 37 | }; 38 | } vec3_t; 39 | 40 | typedef struct 41 | { 42 | union 43 | { 44 | float v[4]; 45 | struct { float x, y, z, w; }; 46 | struct { float r, g, b, a; }; 47 | vec2_t xy; 48 | vec3_t xyz; 49 | vec3_t rgb; 50 | }; 51 | } vec4_t; 52 | 53 | typedef struct 54 | { 55 | union 56 | { 57 | float m[16]; 58 | struct { float m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33; }; 59 | vec4_t c[4]; 60 | }; 61 | } mat4_t; 62 | 63 | static inline int int_min(int a, int b) { return a < b ? a : b; } 64 | static inline int int_max(int a, int b) { return a < b ? b : a; } 65 | static inline int int_clamp(int value, int min, int max) { return value < min ? min : (value < max ? value : max); } 66 | 67 | static inline float float_min(float a, float b) { return a < b ? a : b; } 68 | static inline float float_max(float a, float b) { return a < b ? b : a; } 69 | static inline float float_clamp(float value, float min, float max) { return value < min ? min : (value < max ? value : max); } 70 | 71 | static inline vec2_t vec2(float x, float y) { vec2_t r = { x, y }; return r; } 72 | static inline vec2_t vec2_add(vec2_t v0, vec2_t v1) { vec2_t r = { v0.x + v1.x, v0.y + v1.y }; return r; } 73 | static inline vec2_t vec2_sub(vec2_t v0, vec2_t v1) { vec2_t r = { v0.x - v1.x, v0.y - v1.y }; return r; } 74 | static inline vec2_t vec2_mul(vec2_t v, float f) { vec2_t r = { v.x * f, v.y * f }; return r; } 75 | static inline vec2_t vec2_div(vec2_t v, float f) { float fi = 1.0f / f; vec2_t r = { v.x * fi, v.y * fi }; return r; } 76 | static inline float vec2_dot(vec2_t v0, vec2_t v1) { return v0.x * v1.x + v0.y * v1.y; } 77 | static inline float vec2_cross(vec2_t v0, vec2_t v1) { return v0.x * v1.y - v0.y * v1.x; } 78 | static inline float vec2_length(vec2_t v) { return sqrtf(v.x * v.x + v.y * v.y); } 79 | static inline vec2_t vec2_normalize(vec2_t v) { float fi = 1.0f / sqrtf(v.x * v.x + v.y * v.y); vec2_t r = { v.x * fi, v.y * fi }; return r; } 80 | 81 | static inline vec3_t vec3(float x, float y, float z) { vec3_t r = { x, y, z }; return r; } 82 | static inline vec3_t vec3_2(vec2_t xy, float z) { vec3_t r = { xy.x, xy.y, z }; return r; } 83 | static inline vec3_t vec3_add(vec3_t v0, vec3_t v1) { vec3_t r = { v0.x + v1.x, v0.y + v1.y, v0.z + v1.z }; return r; } 84 | static inline vec3_t vec3_sub(vec3_t v0, vec3_t v1) { vec3_t r = { v0.x - v1.x, v0.y - v1.y, v0.z - v1.z }; return r; } 85 | static inline vec3_t vec3_mul(vec3_t v, float f) { vec3_t r = { v.x * f, v.y * f, v.z * f }; return r; } 86 | static inline vec3_t vec3_div(vec3_t v, float f) { float fi = 1.0f / f; vec3_t r = { v.x * fi, v.y * fi, v.z * fi }; return r; } 87 | static inline float vec3_dot(vec3_t v0, vec3_t v1) { return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z; } 88 | static inline vec3_t vec3_cross(vec3_t v0, vec3_t v1) { vec3_t r = { v0.y * v1.z - v0.z * v1.y, v0.z * v1.x - v0.x * v1.z, v0.x * v1.y - v0.y * v1.x }; return r; } 89 | static inline float vec3_length(vec3_t v) { return sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); } 90 | static inline vec3_t vec3_normalize(vec3_t v) { float fi = 1.0f / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); vec3_t r = { v.x * fi, v.y * fi, v.z * fi }; return r; } 91 | 92 | static inline vec4_t vec4(float x, float y, float z, float w) { vec4_t r = { x, y, z, w }; return r; } 93 | static inline vec4_t vec4_2(vec2_t xy, float z, float w) { vec4_t r = { xy.x, xy.y, z, w }; return r; } 94 | static inline vec4_t vec4_3(vec3_t xyz, float w) { vec4_t r = { xyz.x, xyz.y, xyz.z, w }; return r; } 95 | static inline vec4_t vec4_add(vec4_t v0, vec4_t v1) { vec4_t r = { v0.x + v1.x, v0.y + v1.y, v0.z + v1.z, v0.w + v1.w }; return r; } 96 | static inline vec4_t vec4_sub(vec4_t v0, vec4_t v1) { vec4_t r = { v0.x - v1.x, v0.y - v1.y, v0.z - v1.z, v0.w - v1.w }; return r; } 97 | static inline vec4_t vec4_mul(vec4_t v, float f) { vec4_t r = { v.x * f, v.y * f, v.z * f, v.w * f }; return r; } 98 | static inline vec4_t vec4_div(vec4_t v, float f) { float fi = 1.0f / f; vec4_t r = { v.x * fi, v.y * fi, v.z * fi, v.w * fi }; return r; } 99 | static inline float vec4_dot(vec4_t v0, vec4_t v1) { return v0.x * v1.x + v0.y * v1.y + v0.z * v1.z + v0.w * v1.w; } 100 | static inline vec4_t vec4_cross(vec4_t v0, vec4_t v1) { return vec4_3(vec3_cross(v0.xyz, v1.xyz), (v0.w + v1.w) * 0.5f); } // USUALLY FAIL 101 | static inline float vec4_length(vec4_t v) { return sqrtf(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w); } 102 | static inline vec4_t vec4_normalize(vec4_t v) { float fi = 1.0f / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w); vec4_t r = { v.x * fi, v.y * fi, v.z * fi, v.w * fi }; return r; } 103 | 104 | static inline mat4_t mat4(float m00, float m10, float m20, float m30, float m01, float m11, float m21, float m31, float m02, float m12, float m22, float m32, float m03, float m13, float m23, float m33) 105 | { 106 | mat4_t m = 107 | { 108 | m00, m10, m20, m30, 109 | m01, m11, m21, m31, 110 | m02, m12, m22, m32, 111 | m03, m13, m23, m33 112 | }; 113 | return m; 114 | } 115 | 116 | static inline mat4_t mat4_identity() 117 | { 118 | mat4_t m = 119 | { 120 | 1.0f, 0.0f, 0.0f, 0.0f, 121 | 0.0f, 1.0f, 0.0f, 0.0f, 122 | 0.0f, 0.0f, 1.0f, 0.0f, 123 | 0.0f, 0.0f, 0.0f, 1.0f 124 | }; 125 | return m; 126 | } 127 | 128 | static inline mat4_t mat4_ortho(float left, float right, float bottom, float top, float near, float far) 129 | { 130 | float rl = right - left; 131 | float tx = - (right + left) / rl; 132 | float tb = top - bottom; 133 | float ty = - (top + bottom) / tb; 134 | float fn = far - near; 135 | float tz = - (far + near) / fn; 136 | mat4_t m = 137 | { 138 | 2.0f / rl, 0.0f, 0.0f, 0.0f, 139 | 0.0f, 2.0f / tb, 0.0f, 0.0f, 140 | 0.0f, 0.0f, -2.0f / fn, 0.0f, 141 | tx, ty, tz, 1.0f 142 | }; 143 | return m; 144 | } 145 | 146 | static inline mat4_t mat4_perspective(float fovy, float aspect, float near, float far) 147 | { 148 | float a = fovy * float_pi_over180 * 0.5f; 149 | #ifdef R3D_ARM_MATH 150 | float f = arm_cos_f32(a) / arm_sin_f32(a); 151 | #else 152 | float f = 1.0f / tanf(a); 153 | #endif 154 | float nfi = 1.0f / (near - far); 155 | mat4_t m = 156 | { 157 | f / aspect, 0.0f, 0.0f, 0.0f, 158 | 0.0f, f, 0.0f, 0.0f, 159 | 0.0f, 0.0f, (far + near) * nfi, -1.0f, 160 | 0.0f, 0.0f, 2.0f * far * near * nfi, 0.0f 161 | }; 162 | return m; 163 | } 164 | 165 | static inline mat4_t mat4_mul(mat4_t m0, mat4_t m1) 166 | { 167 | mat4_t m = 168 | { 169 | m0.m00*m1.m00 + m0.m01*m1.m10 + m0.m02*m1.m20 + m0.m03*m1.m30, 170 | m0.m10*m1.m00 + m0.m11*m1.m10 + m0.m12*m1.m20 + m0.m13*m1.m30, 171 | m0.m20*m1.m00 + m0.m21*m1.m10 + m0.m22*m1.m20 + m0.m23*m1.m30, 172 | m0.m30*m1.m00 + m0.m31*m1.m10 + m0.m32*m1.m20 + m0.m33*m1.m30, 173 | 174 | m0.m00*m1.m01 + m0.m01*m1.m11 + m0.m02*m1.m21 + m0.m03*m1.m31, 175 | m0.m10*m1.m01 + m0.m11*m1.m11 + m0.m12*m1.m21 + m0.m13*m1.m31, 176 | m0.m20*m1.m01 + m0.m21*m1.m11 + m0.m22*m1.m21 + m0.m23*m1.m31, 177 | m0.m30*m1.m01 + m0.m31*m1.m11 + m0.m32*m1.m21 + m0.m33*m1.m31, 178 | 179 | m0.m00*m1.m02 + m0.m01*m1.m12 + m0.m02*m1.m22 + m0.m03*m1.m32, 180 | m0.m10*m1.m02 + m0.m11*m1.m12 + m0.m12*m1.m22 + m0.m13*m1.m32, 181 | m0.m20*m1.m02 + m0.m21*m1.m12 + m0.m22*m1.m22 + m0.m23*m1.m32, 182 | m0.m30*m1.m02 + m0.m31*m1.m12 + m0.m32*m1.m22 + m0.m33*m1.m32, 183 | 184 | m0.m00*m1.m03 + m0.m01*m1.m13 + m0.m02*m1.m23 + m0.m03*m1.m33, 185 | m0.m10*m1.m03 + m0.m11*m1.m13 + m0.m12*m1.m23 + m0.m13*m1.m33, 186 | m0.m20*m1.m03 + m0.m21*m1.m13 + m0.m22*m1.m23 + m0.m23*m1.m33, 187 | m0.m30*m1.m03 + m0.m31*m1.m13 + m0.m32*m1.m23 + m0.m33*m1.m33 188 | }; 189 | return m; 190 | } 191 | 192 | static inline mat4_t mat4_translation(vec3_t v) 193 | { 194 | mat4_t m = 195 | { 196 | 1.0f, 0.0f, 0.0f, 0.0f, 197 | 0.0f, 1.0f, 0.0f, 0.0f, 198 | 0.0f, 0.0f, 1.0f, 0.0f, 199 | v.x, v.y, v.z, 1.0f 200 | }; 201 | return m; 202 | } 203 | 204 | static inline mat4_t mat4_lookat(vec3_t eye, vec3_t center, vec3_t up) 205 | { 206 | vec3_t f = vec3_normalize(vec3_sub(center, eye)); 207 | vec3_t s = vec3_cross(f, vec3_normalize(up)); 208 | vec3_t u = vec3_cross(vec3_normalize(s), f); 209 | 210 | mat4_t m = 211 | { 212 | s.x, u.x, -f.x, 0.0f, 213 | s.y, u.y, -f.y, 0.0f, 214 | s.z, u.z, -f.z, 0.0f, 215 | 0.0f, 0.0f, 0.0f, 1.0f 216 | }; 217 | return mat4_mul(m, mat4_translation(vec3_mul(eye, -1.0f))); 218 | } 219 | 220 | static inline mat4_t mat4_scaling(vec3_t v) 221 | { 222 | mat4_t m = 223 | { 224 | v.x, 0.0f, 0.0f, 0.0f, 225 | 0.0f, v.y, 0.0f, 0.0f, 226 | 0.0f, 0.0f, v.z, 0.0f, 227 | 0.0f, 0.0f, 0.0f, 1.0f 228 | }; 229 | return m; 230 | } 231 | 232 | static inline mat4_t mat4_rotation(float angle, vec3_t axis) 233 | { 234 | #ifdef R3D_ARM_MATH 235 | float c, s; 236 | const float i360 = 1.0f / 360.0f; 237 | int a = (int)(angle * i360); 238 | if(angle < 0.0f) a--; 239 | arm_sin_cos_f32(angle - (a * 360.0f) - 180.0f, &c, &s); // accepts [-180, 180] 240 | // = arm_sin_cos_f32(fmod(angle, 360) - 180, &c, &s) 241 | c *= -1.0f; s *= -1.0f; // we're 180° off. correct this 242 | #else 243 | angle *= float_pi_over180; 244 | float c = cosf(angle); 245 | float s = sinf(angle); 246 | #endif 247 | float c2 = 1.0f - c; 248 | axis = vec3_normalize(axis); 249 | float x = axis.x; 250 | float y = axis.y; 251 | float z = axis.z; 252 | 253 | mat4_t m = 254 | { 255 | x*x*c2+c, y*x*c2+z*s, x*z*c2-y*s, 0.0f, 256 | x*y*c2-z*s, y*y*c2+c, y*z*c2+x*s, 0.0f, 257 | x*z*c2+y*s, y*z*c2-x*s, z*z*c2+c, 0.0f, 258 | 0.0f, 0.0f, 0.0f, 1.0f 259 | }; 260 | return m; 261 | } 262 | 263 | static inline vec4_t mat4_transform(mat4_t m, vec4_t v) 264 | { 265 | vec4_t r = 266 | { 267 | m.m00*v.x + m.m01*v.y + m.m02*v.z + m.m03*v.w, 268 | m.m10*v.x + m.m11*v.y + m.m12*v.z + m.m13*v.w, 269 | m.m20*v.x + m.m21*v.y + m.m22*v.z + m.m23*v.w, 270 | m.m30*v.x + m.m31*v.y + m.m32*v.z + m.m33*v.w 271 | }; 272 | return r; 273 | } 274 | 275 | static inline vec3_t mat4_transform_position(mat4_t m, vec3_t v) 276 | { 277 | float fi = 1.0f / (m.m30*v.x + m.m31*v.y + m.m32*v.z + m.m33); 278 | vec3_t r = 279 | { 280 | (m.m00*v.x + m.m01*v.y + m.m02*v.z + m.m03) * fi, 281 | (m.m10*v.x + m.m11*v.y + m.m12*v.z + m.m13) * fi, 282 | (m.m20*v.x + m.m21*v.y + m.m22*v.z + m.m23) * fi 283 | }; 284 | return r; 285 | } 286 | 287 | static inline vec3_t mat4_transform_vector(mat4_t m, vec3_t v) 288 | { 289 | vec3_t r = 290 | { 291 | m.m00*v.x + m.m01*v.y + m.m02*v.z, 292 | m.m10*v.x + m.m11*v.y + m.m12*v.z, 293 | m.m20*v.x + m.m21*v.y + m.m22*v.z 294 | }; 295 | return r; 296 | } 297 | 298 | static inline mat4_t mat4_invert(mat4_t m) 299 | { 300 | mat4_t mi = 301 | { 302 | m.m11*m.m22*m.m33 + m.m12*m.m23*m.m31 + m.m13*m.m21*m.m32 - m.m11*m.m23*m.m32 - m.m12*m.m21*m.m33 - m.m13*m.m22*m.m31, 303 | m.m10*m.m23*m.m32 + m.m12*m.m20*m.m33 + m.m13*m.m22*m.m30 - m.m10*m.m22*m.m33 - m.m12*m.m23*m.m30 - m.m13*m.m20*m.m32, 304 | m.m10*m.m21*m.m33 + m.m11*m.m23*m.m30 + m.m13*m.m20*m.m31 - m.m10*m.m23*m.m31 - m.m11*m.m20*m.m33 - m.m13*m.m21*m.m30, 305 | m.m10*m.m22*m.m31 + m.m11*m.m20*m.m32 + m.m12*m.m21*m.m30 - m.m10*m.m21*m.m32 - m.m11*m.m22*m.m30 - m.m12*m.m20*m.m31, 306 | m.m01*m.m23*m.m32 + m.m02*m.m21*m.m33 + m.m03*m.m22*m.m31 - m.m01*m.m22*m.m33 - m.m02*m.m23*m.m31 - m.m03*m.m21*m.m32, 307 | m.m00*m.m22*m.m33 + m.m02*m.m23*m.m30 + m.m03*m.m20*m.m32 - m.m00*m.m23*m.m32 - m.m02*m.m20*m.m33 - m.m03*m.m22*m.m30, 308 | m.m00*m.m23*m.m31 + m.m01*m.m20*m.m33 + m.m03*m.m31*m.m30 - m.m00*m.m21*m.m33 - m.m01*m.m23*m.m30 - m.m03*m.m20*m.m31, 309 | m.m00*m.m21*m.m32 + m.m01*m.m22*m.m30 + m.m02*m.m20*m.m31 - m.m00*m.m22*m.m31 - m.m01*m.m20*m.m32 - m.m02*m.m21*m.m30, 310 | m.m01*m.m12*m.m33 + m.m02*m.m13*m.m31 + m.m03*m.m11*m.m32 - m.m01*m.m13*m.m32 - m.m02*m.m11*m.m33 - m.m03*m.m12*m.m31, 311 | m.m00*m.m13*m.m32 + m.m02*m.m10*m.m33 + m.m03*m.m12*m.m30 - m.m00*m.m12*m.m33 - m.m02*m.m13*m.m30 - m.m03*m.m10*m.m32, 312 | m.m00*m.m11*m.m33 + m.m01*m.m13*m.m30 + m.m03*m.m10*m.m31 - m.m00*m.m13*m.m31 - m.m01*m.m10*m.m33 - m.m03*m.m11*m.m30, 313 | m.m00*m.m12*m.m31 + m.m01*m.m10*m.m32 + m.m02*m.m11*m.m30 - m.m00*m.m11*m.m32 - m.m01*m.m12*m.m30 - m.m02*m.m10*m.m31, 314 | m.m01*m.m13*m.m22 + m.m02*m.m11*m.m23 + m.m03*m.m12*m.m21 - m.m01*m.m12*m.m23 - m.m02*m.m13*m.m21 - m.m03*m.m11*m.m22, 315 | m.m00*m.m12*m.m23 + m.m02*m.m13*m.m20 + m.m03*m.m10*m.m22 - m.m00*m.m13*m.m22 - m.m02*m.m10*m.m23 - m.m03*m.m12*m.m20, 316 | m.m00*m.m13*m.m21 + m.m01*m.m10*m.m23 + m.m03*m.m11*m.m20 - m.m00*m.m11*m.m23 - m.m01*m.m13*m.m20 - m.m03*m.m10*m.m21, 317 | m.m00*m.m11*m.m22 + m.m01*m.m12*m.m20 + m.m02*m.m10*m.m21 - m.m00*m.m12*m.m21 - m.m01*m.m10*m.m22 - m.m02*m.m11*m.m20, 318 | }; 319 | return mi; 320 | } 321 | 322 | static inline mat4_t mat4_transpose(mat4_t m) 323 | { 324 | mat4_t mt = 325 | { 326 | m.m00, m.m01, m.m02, m.m03, 327 | m.m10, m.m11, m.m12, m.m13, 328 | m.m20, m.m21, m.m22, m.m23, 329 | m.m30, m.m31, m.m32, m.m33 330 | }; 331 | return mt; 332 | } 333 | 334 | #endif 335 | -------------------------------------------------------------------------------- /libs/r3dfb-sdl/r3dfb.c: -------------------------------------------------------------------------------- 1 | /***************************************************** 2 | * r3dfb -- 3D rendering library framebuffer for SDL * 3 | * author: rene-dev, Andreas Mantler (ands) * 4 | *****************************************************/ 5 | 6 | #include 7 | #include 8 | #include "r3d.h" 9 | #include "r3dfb.h" 10 | 11 | static SDL_Window* window; 12 | static SDL_Surface* surface; 13 | static float depthbuffer[R3DFB_PIXEL_WIDTH * R3DFB_PIXEL_HEIGHT]; 14 | static uint32_t *colorbuffer; 15 | 16 | void r3dfb_init(void) 17 | { 18 | SDL_Init(SDL_INIT_VIDEO); 19 | window = SDL_CreateWindow("r3dfb-sdl", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, R3DFB_PIXEL_WIDTH, R3DFB_PIXEL_HEIGHT, SDL_WINDOW_SHOWN); 20 | surface = SDL_GetWindowSurface(window); 21 | colorbuffer = (uint32_t*)surface->pixels; 22 | } 23 | 24 | void r3dfb_clear(void) 25 | { 26 | memset(depthbuffer, 0x00, R3DFB_DEPTH_BUFFER_SIZE); 27 | memset(colorbuffer, 0xff, R3DFB_COLOR_BUFFER_SIZE); 28 | } 29 | 30 | void r3dfb_swap_buffers(void) 31 | { 32 | SDL_UpdateWindowSurface(window); 33 | SDL_Event event; 34 | while(SDL_PollEvent(&event)) 35 | { 36 | if(event.type == SDL_QUIT) 37 | { 38 | SDL_Quit(); 39 | exit(0); 40 | } 41 | } 42 | } 43 | 44 | // r3d interface 45 | void r3d_set_pixel(uint16_t x, uint16_t y, float z, vec3_t color) 46 | { 47 | depthbuffer[y * R3DFB_PIXEL_WIDTH + x] = z; 48 | colorbuffer[y * R3DFB_PIXEL_WIDTH + x] = 0xff000000 | (int)(color.r * 255) << 16 | (int)(color.g * 255) << 8 | (int)(color.b * 255); // ARGB 49 | } 50 | 51 | float r3d_get_depth(uint16_t x, uint16_t y) 52 | { 53 | return depthbuffer[y * R3DFB_PIXEL_WIDTH + x]; 54 | } 55 | -------------------------------------------------------------------------------- /libs/r3dfb-sdl/r3dfb.h: -------------------------------------------------------------------------------- 1 | /***************************************************** 2 | * r3dfb -- 3D rendering library framebuffer for SDL * 3 | * author: rene-dev, Andreas Mantler (ands) * 4 | *****************************************************/ 5 | 6 | #ifndef R3DFB_H 7 | #define R3DFB_H 8 | 9 | #define R3DFB_PIXEL_WIDTH ((uint16_t)800) 10 | #define R3DFB_PIXEL_HEIGHT ((uint16_t)600) 11 | 12 | #define R3DFB_COLOR_BUFFER_SIZE (R3DFB_PIXEL_WIDTH * R3DFB_PIXEL_HEIGHT * sizeof(uint32_t)) 13 | #define R3DFB_DEPTH_BUFFER_SIZE (R3DFB_PIXEL_WIDTH * R3DFB_PIXEL_HEIGHT * sizeof(float)) 14 | 15 | void r3dfb_init(void); 16 | void r3dfb_clear(void); // clears color back buffer and depth buffer 17 | void r3dfb_swap_buffers(void); // flushes back to front color buffer 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /libs/r3dfb-stm32f429-discovery/r3dfb.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * r3dfb -- 3D rendering library framebuffer for STM32F429-DISCOVERY * 3 | * author: Andreas Mantler (ands) * 4 | *********************************************************************/ 5 | 6 | #include "stm32f4xx.h" 7 | #include "stm32f429i_discovery.h" 8 | #include "stm32f429i_discovery_lcd.h" 9 | #include "r3d.h" 10 | #include "r3dfb.h" 11 | 12 | static uint32_t r3dfb_front_buffer = R3DFB_BUFFER0; 13 | static uint32_t r3dfb_back_buffer = R3DFB_BUFFER1; 14 | 15 | void r3dfb_init(void) 16 | { 17 | LCD_Init(); 18 | 19 | LTDC_Layer_InitTypeDef LTDC_Layer_InitStruct; 20 | LTDC_Layer_InitStruct.LTDC_HorizontalStart = 30; 21 | LTDC_Layer_InitStruct.LTDC_HorizontalStop = (R3DFB_PIXEL_WIDTH + 30 - 1); 22 | LTDC_Layer_InitStruct.LTDC_VerticalStart = 4; 23 | LTDC_Layer_InitStruct.LTDC_VerticalStop = (R3DFB_PIXEL_HEIGHT + 4 - 1); 24 | LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565; 25 | LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255; 26 | LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = 0; 27 | LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = 0; 28 | LTDC_Layer_InitStruct.LTDC_DefaultColorRed = 0; 29 | LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = 0; 30 | LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA; 31 | LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA; 32 | LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((R3DFB_PIXEL_WIDTH * 2) + 3); 33 | LTDC_Layer_InitStruct.LTDC_CFBPitch = (R3DFB_PIXEL_WIDTH * 2); 34 | LTDC_Layer_InitStruct.LTDC_CFBLineNumber = R3DFB_PIXEL_HEIGHT; 35 | LTDC_Layer_InitStruct.LTDC_CFBStartAdress = r3dfb_front_buffer; 36 | LTDC_LayerInit(LTDC_Layer1, <DC_Layer_InitStruct); 37 | 38 | LTDC_LayerCmd(LTDC_Layer1, ENABLE); 39 | LTDC_LayerCmd(LTDC_Layer2, DISABLE); 40 | 41 | LTDC_ReloadConfig(LTDC_IMReload); 42 | 43 | LTDC_Cmd(ENABLE); 44 | } 45 | 46 | void r3dfb_clear(void) 47 | { 48 | memset((void*)R3DFB_DEPTH_BUFFER, 0, R3DFB_DEPTH_BUFFER_SIZE); 49 | memset((void*)r3dfb_back_buffer, 0xff, R3DFB_COLOR_BUFFER_SIZE); 50 | } 51 | 52 | void r3dfb_swap_buffers(void) 53 | { 54 | uint32_t tmp = r3dfb_front_buffer; 55 | r3dfb_front_buffer = r3dfb_back_buffer; 56 | r3dfb_back_buffer = tmp; 57 | 58 | // hack for font rendering 59 | LCD_SetLayer(r3dfb_back_buffer == R3DFB_BUFFER0 ? LCD_BACKGROUND_LAYER : LCD_FOREGROUND_LAYER); 60 | 61 | LTDC_Cmd(DISABLE); 62 | LTDC_LayerAddress(LTDC_Layer1, r3dfb_front_buffer); 63 | LTDC_ReloadConfig(LTDC_IMReload); 64 | LTDC_Cmd(ENABLE); 65 | } 66 | 67 | // r3d interface 68 | void r3d_set_pixel(uint16_t x, uint16_t y, float z, vec3_t color) 69 | { 70 | // convert color to RGB565 71 | uint16_t c = ((uint16_t)(color.r * 63488.0f) & 63488) | 72 | ((uint16_t)(color.g * 2016.0f) & 2016) | 73 | ((uint16_t)(color.b * 31.0f) & 31); 74 | // set color + depth 75 | const uint32_t offset = 2 * (x + R3DFB_PIXEL_WIDTH * y); 76 | *(__IO uint16_t*) (r3dfb_back_buffer + offset) = c; 77 | *(__IO uint16_t*) (R3DFB_DEPTH_BUFFER + offset) = z * 65535.0f; 78 | } 79 | 80 | float r3d_get_depth(uint16_t x, uint16_t y) 81 | { 82 | const float uint16to1f = 1.0f / 65535.0f; 83 | const uint32_t offset = 2 * (x + R3DFB_PIXEL_WIDTH * y); 84 | return (*(__IO uint16_t*) (R3DFB_DEPTH_BUFFER + offset)) * uint16to1f; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /libs/r3dfb-stm32f429-discovery/r3dfb.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * r3dfb -- 3D rendering library framebuffer for STM32F429-DISCOVERY * 3 | * author: Andreas Mantler (ands) * 4 | *********************************************************************/ 5 | 6 | #ifndef R3DFB_H 7 | #define R3DFB_H 8 | 9 | #define R3DFB_PIXEL_WIDTH ((uint16_t)240) 10 | #define R3DFB_PIXEL_HEIGHT ((uint16_t)320) 11 | 12 | #define R3DFB_COLOR_BUFFER_SIZE (R3DFB_PIXEL_WIDTH * R3DFB_PIXEL_HEIGHT * sizeof(uint16_t)) 13 | #define R3DFB_DEPTH_BUFFER_SIZE (R3DFB_PIXEL_WIDTH * R3DFB_PIXEL_HEIGHT * sizeof(uint16_t)) 14 | 15 | #define R3DFB_BUFFER_OFFSET ((uint32_t)0x50000) 16 | #define R3DFB_BUFFER0 ((uint32_t)0xD0000000) 17 | #define R3DFB_BUFFER1 (R3DFB_BUFFER0 + R3DFB_BUFFER_OFFSET) 18 | #define R3DFB_DEPTH_BUFFER (R3DFB_BUFFER1 + R3DFB_BUFFER_OFFSET) 19 | 20 | void r3dfb_init(void); 21 | void r3dfb_clear(void); // clears color back buffer and depth buffer 22 | void r3dfb_swap_buffers(void); // swaps back and front color buffers 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /nyanpot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ands/libr3d/d421d44757e14b8120086a6b1912bc6bea0f6998/nyanpot.png -------------------------------------------------------------------------------- /pony.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ands/libr3d/d421d44757e14b8120086a6b1912bc6bea0f6998/pony.png --------------------------------------------------------------------------------