├── docs ├── images │ ├── frame.png │ ├── pcb_hdmi.webp │ ├── pcb_main.webp │ ├── prototype.webp │ └── finished_install.webp ├── font.md ├── building_hardware.md └── impl_details.md ├── hardware ├── wii_flex │ ├── README.md │ ├── fp-lib-table │ ├── library.pretty │ │ └── wii_pin.kicad_mod │ ├── wii_flex.kicad_pro │ └── LICENSE ├── wii_mainboard │ ├── README.md │ ├── fp-lib-table │ ├── sym-lib-table │ ├── wii_mainboard.kicad_dru │ ├── 74AVC16T245DGGRE4.kicad_sym │ └── wii_mainboard.kicad_pro └── hdmi_pcb │ ├── README.md │ ├── wii_hdmi_pcb.kicad_dru │ └── wii_hdmi_pcb.kicad_pro ├── .editorconfig ├── hardware_xosc ├── CMakeLists.txt ├── README.md ├── include │ └── hardware │ │ └── xosc.h └── xosc.c ├── src ├── pio │ ├── clock.pio │ ├── serializer.pio │ ├── i2s.pio │ └── capture.pio ├── font.h ├── packet_info_frame.h ├── tmds_clock.h ├── config.h ├── str_builder.c ├── str_builder.h ├── gpu_input.h ├── frame.h ├── video_output.h ├── packets.h ├── tmds_clock.c ├── tmds_serializer.h ├── utils.h ├── tmds_encode.h ├── mem_pool.c ├── mem_pool.h ├── packet_info_frame.c ├── tmds_serializer.c ├── packets.c ├── ffifo.h ├── gpu_input.c ├── video_output.c ├── tmds_encode.c ├── font.c └── main.c ├── .clang-format ├── CMakeLists.txt ├── README.md └── pico_sdk_import.cmake /docs/images/frame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtreme8000/picoAVE/HEAD/docs/images/frame.png -------------------------------------------------------------------------------- /docs/images/pcb_hdmi.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtreme8000/picoAVE/HEAD/docs/images/pcb_hdmi.webp -------------------------------------------------------------------------------- /docs/images/pcb_main.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtreme8000/picoAVE/HEAD/docs/images/pcb_main.webp -------------------------------------------------------------------------------- /docs/images/prototype.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtreme8000/picoAVE/HEAD/docs/images/prototype.webp -------------------------------------------------------------------------------- /hardware/wii_flex/README.md: -------------------------------------------------------------------------------- 1 | License: [CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/) 2 | -------------------------------------------------------------------------------- /hardware/wii_mainboard/README.md: -------------------------------------------------------------------------------- 1 | License: [CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/) 2 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | indent_style = tab 3 | indent_size = 4 4 | end_of_line = lf 5 | trim_trailing_whitespace = true 6 | -------------------------------------------------------------------------------- /docs/images/finished_install.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xtreme8000/picoAVE/HEAD/docs/images/finished_install.webp -------------------------------------------------------------------------------- /hardware_xosc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | pico_simple_hardware_target(xosc) 2 | pico_mirrored_target_link_libraries(hardware_xosc INTERFACE hardware_clocks) -------------------------------------------------------------------------------- /hardware/wii_flex/fp-lib-table: -------------------------------------------------------------------------------- 1 | (fp_lib_table 2 | (version 7) 3 | (lib (name "library")(type "KiCad")(uri "${KIPRJMOD}/library.pretty")(options "")(descr "")) 4 | ) 5 | -------------------------------------------------------------------------------- /hardware/wii_mainboard/fp-lib-table: -------------------------------------------------------------------------------- 1 | (fp_lib_table 2 | (version 7) 3 | (lib (name "library")(type "KiCad")(uri "${KIPRJMOD}/library.pretty")(options "")(descr "")) 4 | ) 5 | -------------------------------------------------------------------------------- /hardware/hdmi_pcb/README.md: -------------------------------------------------------------------------------- 1 | Adapted from https://github.com/wmi-0/wiihdmi/tree/master/hdmi_pcb/kicad 2 | 3 | License: [GPL v3](https://github.com/wmi-0/wiihdmi/blob/master/LICENSE) 4 | -------------------------------------------------------------------------------- /hardware/wii_mainboard/sym-lib-table: -------------------------------------------------------------------------------- 1 | (sym_lib_table 2 | (version 7) 3 | (lib (name "74AVC16T245DGGRE4")(type "KiCad")(uri "${KIPRJMOD}/74AVC16T245DGGRE4.kicad_sym")(options "")(descr "")) 4 | ) 5 | -------------------------------------------------------------------------------- /hardware_xosc/README.md: -------------------------------------------------------------------------------- 1 | This overrides the pico-sdk's own hardware_xosc to prevent a [compile error](https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2_common/hardware_xosc/xosc.c#L19) on any clock input frequency higher than 50MHz (we need 54MHz). 2 | -------------------------------------------------------------------------------- /src/pio/clock.pio: -------------------------------------------------------------------------------- 1 | .program pio_clock 2 | 3 | nop 4 | nop 5 | loop: 6 | set pins, 0b01 [4] 7 | set pins, 0b10 [3] 8 | jmp loop 9 | 10 | % c-sdk { 11 | static inline void pio_clock_program_init(PIO pio, uint sm, uint offset, uint pin_base) { 12 | for(uint k = pin_base; k < pin_base + 2; k++) { 13 | pio_gpio_init(pio, k); 14 | pio_sm_set_consecutive_pindirs(pio, sm, k, 1, true); 15 | gpio_set_slew_rate(k, GPIO_SLEW_RATE_SLOW); 16 | gpio_set_drive_strength(k, GPIO_DRIVE_STRENGTH_2MA); 17 | } 18 | 19 | pio_sm_config c = pio_clock_program_get_default_config(offset); 20 | sm_config_set_set_pins(&c, pin_base, 2); 21 | pio_sm_init(pio, sm, offset, &c); 22 | pio_sm_set_enabled(pio, sm, false); 23 | } 24 | %} 25 | -------------------------------------------------------------------------------- /hardware/wii_flex/library.pretty/wii_pin.kicad_mod: -------------------------------------------------------------------------------- 1 | (footprint "wii_pin" (version 20221018) (generator pcbnew) 2 | (layer "F.Cu") 3 | (descr "solder Pin_ with flat fork, hole diameter 0.7mm, length 6.5mm, width 1.8mm") 4 | (tags "solder Pin_ with flat fork") 5 | (attr through_hole) 6 | (fp_text reference "REF**" (at 0 1.8) (layer "F.SilkS") hide 7 | (effects (font (size 1 1) (thickness 0.15))) 8 | (tstamp b648ac41-e99b-4b44-bb62-2d7e27666e78) 9 | ) 10 | (fp_text value "Pin_D0.7mm_L6.5mm_W1.8mm_FlatFork" (at 0 -2.54) (layer "F.Fab") hide 11 | (effects (font (size 1 1) (thickness 0.15))) 12 | (tstamp 23741efe-d2b5-4e3c-9194-162a2dda2fac) 13 | ) 14 | (pad "1" thru_hole circle (at 0 0) (size 0.68 0.68) (drill 0.32) (layers "*.Cu" "*.Mask") (tstamp a51017a3-63e6-48fe-ae2a-9cc5524a1e45)) 15 | ) 16 | -------------------------------------------------------------------------------- /hardware_xosc/include/hardware/xosc.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef _HARDWARE_XOSC_H 21 | #define _HARDWARE_XOSC_H 22 | 23 | void xosc_init(void); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/font.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef FONT_H 21 | #define FONT_H 22 | 23 | #include 24 | #include 25 | 26 | #define FONT_CHAR_WIDTH 8 27 | #define FONT_CHAR_HEIGHT 16 28 | 29 | size_t font_encode(const char* str, size_t y, uint32_t* pixbuf); 30 | size_t font_width(const char* str); 31 | 32 | #endif -------------------------------------------------------------------------------- /docs/font.md: -------------------------------------------------------------------------------- 1 | ## Generate embedded font data 2 | 3 | First use [monobit](https://github.com/robhagemans/monobit) to convert a font (monospace, 8x16) to png. 4 | 5 | ```bash 6 | ./convert.py font.bdf to font.png 7 | ``` 8 | 9 | Then run this script. 10 | 11 | ```python 12 | from PIL import Image 13 | 14 | im = Image.open('font.png') 15 | 16 | char_size = (8, 16) 17 | chars_skipped = 32 18 | chars_line = 32 19 | 20 | assert char_size[0] <= 8 21 | assert im.size[0] == chars_line * (char_size[0] + 1) - 1 22 | assert im.size[1] >= int((128 - chars_skipped + chars_line - 1) / chars_line) * (char_size[1] + 1) - 1 23 | 24 | encoded = [] 25 | 26 | for y in range(char_size[1]): 27 | for k in range(128 - chars_skipped): 28 | offset = (int(k % chars_line) * (char_size[0] + 1), int(k / chars_line) * (char_size[1] + 1)) 29 | out = 0 30 | 31 | for x in range(char_size[0]): 32 | avg = sum(im.getpixel((x + offset[0], y + offset[1]))) 33 | out = (0x80 if avg > 0 else 0) | (out >> 1) 34 | 35 | encoded.append(f'0x{out:02x}, ') 36 | 37 | print(''.join(encoded)) 38 | ``` -------------------------------------------------------------------------------- /src/pio/serializer.pio: -------------------------------------------------------------------------------- 1 | .program pio_serializer 2 | .side_set 2 3 | .origin 0 4 | 5 | .wrap_target 6 | out pc, 1 side 0b10 7 | out pc, 1 side 0b01 8 | .wrap 9 | 10 | % c-sdk { 11 | static inline void pio_serializer_program_init(PIO pio, uint sm, uint offset, uint pin_base) { 12 | // TODO: okay to remove? 13 | pio_sm_set_pins_with_mask(pio, sm, 2u << pin_base, 3u << pin_base); 14 | pio_sm_set_pindirs_with_mask(pio, sm, ~0u, 3u << pin_base); 15 | 16 | for(uint k = pin_base; k < pin_base + 2; k++) { 17 | pio_gpio_init(pio, k); 18 | //pio_sm_set_consecutive_pindirs(pio, sm, k, 1, true); 19 | gpio_set_slew_rate(k, GPIO_SLEW_RATE_SLOW); 20 | gpio_set_drive_strength(k, GPIO_DRIVE_STRENGTH_2MA); 21 | } 22 | 23 | pio_sm_config c = pio_serializer_program_get_default_config(offset); 24 | sm_config_set_sideset_pins(&c, pin_base); 25 | sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); 26 | sm_config_set_out_shift(&c, true, true, 20); 27 | pio_sm_init(pio, sm, offset, &c); 28 | pio_sm_set_enabled(pio, sm, false); 29 | } 30 | %} 31 | -------------------------------------------------------------------------------- /src/packet_info_frame.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef PACKET_INFO_FRAME 21 | #define PACKET_INFO_FRAME 22 | 23 | #include "packets.h" 24 | 25 | void packet_avi_info(struct packet* p); 26 | void packet_spd_info(struct packet* p, const char* vendor, const char* product); 27 | void packet_audio_info(struct packet* p, size_t samplerate); 28 | void packet_audio_clk_regen(struct packet* p, uint32_t n, uint32_t cts); 29 | 30 | #endif -------------------------------------------------------------------------------- /src/tmds_clock.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef TMDS_CLOCK_H 21 | #define TMDS_CLOCK_H 22 | 23 | #include "pico/platform.h" 24 | #include "tmds_serializer.h" 25 | 26 | struct tmds_clock { 27 | uint pio_sm; 28 | }; 29 | 30 | void tmds_clock_init(void); 31 | void tmds_clock_create(struct tmds_clock* s, uint gpio_base); 32 | void tmds_start_with_clock(struct tmds_clock* c, struct tmds_serializer* s, 33 | size_t length); 34 | 35 | #endif -------------------------------------------------------------------------------- /hardware_xosc/xosc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #include "hardware/structs/xosc.h" 21 | #include "hardware/xosc.h" 22 | #include "pico.h" 23 | 24 | void xosc_init() { 25 | xosc_hw->ctrl = XOSC_CTRL_FREQ_RANGE_VALUE_1_15MHZ; 26 | xosc_hw->startup = 8192 - 1; 27 | hw_set_bits(&xosc_hw->ctrl, 28 | XOSC_CTRL_ENABLE_VALUE_ENABLE << XOSC_CTRL_ENABLE_LSB); 29 | 30 | while(!(xosc_hw->status & XOSC_STATUS_STABLE_BITS)) 31 | tight_loop_contents(); 32 | } -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef CONFIG_H 21 | #define CONFIG_H 22 | 23 | #define PROJECT_NAME "picoAVE" 24 | #define PROJECT_VERSION "v0.1" 25 | 26 | #define BOARD_LED0 12 27 | #define BOARD_LED1 13 28 | 29 | #define BOARD_VIDEO_BASE 18 30 | 31 | #define BOARD_AUDIO_BASE 28 32 | #define BOARD_AUDIO_WS 27 33 | 34 | #define BOARD_TMDS_0 6 35 | #define BOARD_TMDS_1 4 36 | #define BOARD_TMDS_2 2 37 | #define BOARD_TMDS_CLK 10 38 | 39 | #endif -------------------------------------------------------------------------------- /src/str_builder.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #include "str_builder.h" 21 | 22 | char* str_append(char* s, char* a) { 23 | while(*a) 24 | *(s++) = *(a++); 25 | 26 | return s; 27 | } 28 | 29 | char* str_uint(char* s, uint32_t i) { 30 | char buf[10]; 31 | char* last = buf; 32 | 33 | while(1) { 34 | *(last++) = (i % 10) + '0'; 35 | i /= 10; 36 | 37 | if(!i) 38 | break; 39 | } 40 | 41 | while(buf != last) 42 | *(s++) = *(--last); 43 | 44 | return s; 45 | } -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: WebKit 3 | AlignAfterOpenBracket: Align 4 | AlignConsecutiveAssignments: 'false' 5 | AlignConsecutiveDeclarations: 'false' 6 | AlignTrailingComments: 'true' 7 | AllowAllParametersOfDeclarationOnNextLine: 'true' 8 | AllowShortBlocksOnASingleLine: 'true' 9 | AllowShortCaseLabelsOnASingleLine: 'true' 10 | AllowShortFunctionsOnASingleLine: Empty 11 | AllowShortIfStatementsOnASingleLine: 'false' 12 | AllowShortLoopsOnASingleLine: 'false' 13 | AlwaysBreakAfterDefinitionReturnType: None 14 | AlwaysBreakAfterReturnType: None 15 | AlwaysBreakBeforeMultilineStrings: 'false' 16 | BreakBeforeBraces: Attach 17 | BreakBeforeTernaryOperators: 'false' 18 | Cpp11BracedListStyle: 'true' 19 | ExperimentalAutoDetectBinPacking: 'false' 20 | IndentCaseLabels: 'true' 21 | KeepEmptyLinesAtTheStartOfBlocks: 'false' 22 | Language: Cpp 23 | PointerAlignment: Left 24 | SortIncludes: 'true' 25 | SpaceAfterCStyleCast: 'false' 26 | SpaceBeforeAssignmentOperators: 'true' 27 | SpaceBeforeParens: Never 28 | SpaceInEmptyParentheses: 'false' 29 | SpacesInCStyleCastParentheses: 'false' 30 | SpacesInParentheses: 'false' 31 | SpacesInSquareBrackets: 'false' 32 | TabWidth: '4' 33 | UseTab: Always 34 | MaxEmptyLinesToKeep: 1 35 | ReflowComments: 'true' 36 | ColumnLimit: '80' 37 | 38 | ... 39 | -------------------------------------------------------------------------------- /src/str_builder.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef STR_BUILDER_H 21 | #define STR_BUILDER_H 22 | 23 | #include 24 | 25 | /** 26 | * Finish the string. Appends a zero character. 27 | */ 28 | static inline void str_finish(char* s) { 29 | *s = 0; 30 | } 31 | 32 | /** 33 | * Append a single character to the string. 34 | */ 35 | static inline char* str_char(char* s, char c) { 36 | *(s++) = c; 37 | return s; 38 | } 39 | 40 | /** 41 | * Append another string to the string. 42 | */ 43 | char* str_append(char* s, char* a); 44 | 45 | /** 46 | * Append an unsigned int to the string. 47 | */ 48 | char* str_uint(char* s, uint32_t i); 49 | 50 | #endif -------------------------------------------------------------------------------- /src/pio/i2s.pio: -------------------------------------------------------------------------------- 1 | .program pio_i2s 2 | 3 | // EXECCTRL_JMP_PIN = WS 4 | // PIN 0 = SD 5 | // PIN 1 = SCK 6 | // 16 bits, msb first, right justified 7 | 8 | .wrap_target 9 | left: 10 | wait 0 pin 1 11 | wait 1 pin 1 12 | jmp pin, left_continue 13 | left_end: 14 | mov x, isr 15 | jmp right_continue 16 | 17 | right: 18 | wait 0 pin 1 19 | wait 1 pin 1 20 | jmp pin, right_end 21 | right_continue: 22 | in pins, 1 23 | jmp right 24 | right_end: 25 | in x, 16 26 | push block 27 | // jmp left_continue 28 | 29 | left_continue: 30 | in pins, 1 31 | // jmp left 32 | .wrap 33 | 34 | % c-sdk { 35 | static inline void pio_i2s_program_init(PIO pio, uint sm, uint offset, uint pin_base, uint pin_ws) { 36 | for(uint k = pin_base; k < pin_base + 2; k++) { 37 | gpio_init(k); 38 | gpio_set_input_enabled(k, true); 39 | gpio_disable_pulls(k); 40 | } 41 | 42 | gpio_init(pin_ws); 43 | gpio_set_input_enabled(pin_ws, true); 44 | gpio_disable_pulls(pin_ws); 45 | 46 | pio_sm_config c = pio_i2s_program_get_default_config(offset); 47 | sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX); 48 | sm_config_set_in_shift(&c, false, false, 32); 49 | sm_config_set_in_pins(&c, pin_base); 50 | sm_config_set_jmp_pin(&c, pin_ws); 51 | pio_sm_init(pio, sm, offset, &c); 52 | pio_sm_set_enabled(pio, sm, false); 53 | } 54 | %} -------------------------------------------------------------------------------- /src/gpu_input.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef GPU_INPUT_H 21 | #define GPU_INPUT_H 22 | 23 | #include "mem_pool.h" 24 | #include "pico/platform.h" 25 | 26 | struct gpu_data { 27 | bool data_skipped; 28 | size_t length; 29 | uint32_t* ptr; 30 | }; 31 | 32 | #define AUDIO_FRAME_LENGTH 192 33 | 34 | struct audio_data { 35 | uint32_t samplerate; 36 | uint32_t audio_data[AUDIO_FRAME_LENGTH]; 37 | }; 38 | 39 | void gpu_input_init(size_t capacity, size_t buffer_length, uint video_base, 40 | struct mem_pool* pool_audio, queue_t* receive_queue_audio, 41 | uint audio_base, uint audio_ws); 42 | void gpu_input_start(void); 43 | struct gpu_data* gpu_input_receive(void); 44 | void gpu_input_release(struct gpu_data* d); 45 | void gpu_input_drain(bool shifted); 46 | 47 | #endif -------------------------------------------------------------------------------- /src/frame.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef FRAME_H 21 | #define FRAME_H 22 | 23 | #define FRAME_CLOCK 270000 24 | 25 | #define FRAME_H_SYNC 62 26 | #define FRAME_H_PORCH_FRONT 16 27 | #define FRAME_H_PORCH_BACK 60 28 | #define FRAME_H_BLANK (FRAME_H_PORCH_FRONT + FRAME_H_SYNC + FRAME_H_PORCH_BACK) 29 | 30 | #define FRAME_V_SYNC 6 31 | #define FRAME_V_PORCH_FRONT 9 32 | #define FRAME_V_PORCH_BACK 30 33 | #define FRAME_V_BLANK (FRAME_V_PORCH_FRONT + FRAME_V_SYNC + FRAME_V_PORCH_BACK) 34 | 35 | #define FRAME_VIS_WIDTH 720 36 | #define FRAME_VIS_HEIGHT 480 37 | 38 | #define FRAME_WIDTH (FRAME_H_BLANK + FRAME_VIS_WIDTH) 39 | #define FRAME_HEIGHT (FRAME_V_BLANK + FRAME_VIS_HEIGHT) 40 | 41 | #define FRAME_BUFFER_OFFSET 10 42 | #define FRAME_BUFFER_WIDTH (FRAME_VIS_WIDTH + FRAME_BUFFER_OFFSET) 43 | 44 | #endif -------------------------------------------------------------------------------- /src/pio/capture.pio: -------------------------------------------------------------------------------- 1 | .program pio_capture 2 | 3 | .wrap_target 4 | // exactly 5 (interlaced: 10) cycles for each byte (270MHz / 54MHz) 5 | // using csel as a clock 6 | 7 | wait 1 pin 8 // wait for rising edge 8 | 9 | in pins, 8 [4] // y1 10 | in pins, 8 // cb 11 | 12 | wait 0 pin 8 // wait for falling edge 13 | 14 | in pins, 8 [4] // y2 15 | in pins, 8 // cr 16 | .wrap 17 | 18 | .program pio_capture_shifted 19 | 20 | .wrap_target 21 | wait 0 pin 8 // wait for falling edge 22 | 23 | in pins, 8 [4] // y1 24 | mov x, pins // cr 25 | 26 | wait 1 pin 8 // wait for rising edge 27 | 28 | mov y, pins [4] // y2 29 | in pins, 8 // cb 30 | in y, 8 31 | in x, 8 32 | .wrap 33 | 34 | % c-sdk { 35 | static inline void pio_capture_program_init(PIO pio, uint sm, uint offset, uint pin_base) { 36 | for(uint k = pin_base; k < pin_base + 9; k++) { 37 | gpio_init(k); 38 | gpio_set_input_enabled(k, true); 39 | gpio_set_dir(k, false); 40 | gpio_set_input_hysteresis_enabled(k, true); 41 | gpio_disable_pulls(k); 42 | } 43 | 44 | pio_sm_config c = pio_capture_program_get_default_config(offset); 45 | sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX); 46 | sm_config_set_in_shift(&c, false, true, 32); 47 | sm_config_set_in_pins(&c, pin_base); 48 | pio_sm_init(pio, sm, offset, &c); 49 | pio_sm_set_enabled(pio, sm, false); 50 | } 51 | %} 52 | -------------------------------------------------------------------------------- /src/video_output.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef VIDEO_OUTPUT_H 21 | #define VIDEO_OUTPUT_H 22 | 23 | #include "mem_pool.h" 24 | #include "pico/util/queue.h" 25 | #include "tmds_serializer.h" 26 | 27 | #define TMDS_CHANNEL_COUNT 3 28 | 29 | struct tmds_data3 { 30 | enum tmds_data_type { 31 | TYPE_CONST, 32 | TYPE_VIDEO, 33 | TYPE_PACKET, 34 | } type; 35 | bool vsync; 36 | size_t encode_offset; 37 | size_t encode_length; 38 | size_t length; 39 | uint32_t* ptr[TMDS_CHANNEL_COUNT]; 40 | size_t transfers; 41 | }; 42 | 43 | void video_output_init(uint gpio_channels[TMDS_CHANNEL_COUNT], uint gpio_clk, 44 | struct mem_pool* pool_video, 45 | struct mem_pool* pool_packets); 46 | void video_output_start(void); 47 | void video_output_submit(struct tmds_data3* data); 48 | void video_output_set_audio_info(uint32_t samplerate); 49 | 50 | #endif -------------------------------------------------------------------------------- /src/packets.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef PACKETS_H 21 | #define PACKETS_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #define PACKET_HEADER_LENGTH 4 28 | #define PACKET_BODY_LENGTH 32 29 | #define PACKET_SUBLANE_LENGTH 8 30 | #define PACKET_SUBLANE_COUNT (PACKET_BODY_LENGTH / PACKET_SUBLANE_LENGTH) 31 | 32 | struct packet { 33 | uint8_t header[PACKET_HEADER_LENGTH]; 34 | uint8_t data[PACKET_BODY_LENGTH]; 35 | }; 36 | 37 | void packets_init(void); 38 | void packets_encode(struct packet* p, size_t amount, bool hsync, bool vsync, 39 | uint32_t* tmds0, uint32_t* tmds1, uint32_t* tmds2); 40 | void packets_encode_audio(uint32_t samples[4], size_t frame, bool hsync, 41 | bool vsync, uint32_t* tmds0, uint32_t* tmds1, 42 | uint32_t* tmds2); 43 | size_t packets_length(size_t amount); 44 | 45 | #endif -------------------------------------------------------------------------------- /src/tmds_clock.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include "clock.pio.h" 23 | #include "tmds_clock.h" 24 | 25 | static uint pio_program_offset; 26 | 27 | void tmds_clock_init() { 28 | pio_program_offset = pio_add_program(pio0, &pio_clock_program); 29 | } 30 | 31 | void tmds_clock_create(struct tmds_clock* s, uint gpio_base) { 32 | assert(s && gpio_base < 32 && (gpio_base % 2) == 0); 33 | 34 | s->pio_sm = pio_claim_unused_sm(pio0, true); 35 | pio_clock_program_init(pio0, s->pio_sm, pio_program_offset, gpio_base); 36 | } 37 | 38 | void tmds_start_with_clock(struct tmds_clock* c, struct tmds_serializer* s, 39 | size_t length) { 40 | assert(c && s && length > 0); 41 | uint32_t mask = 1 << c->pio_sm; 42 | 43 | for(size_t k = 0; k < length; k++) 44 | mask |= 1 << s[k].pio_sm; 45 | 46 | pio_enable_sm_mask_in_sync(pio0, mask); 47 | } -------------------------------------------------------------------------------- /src/tmds_serializer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef TMDS_SERIALIZER_H 21 | #define TMDS_SERIALIZER_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "ffifo.h" 28 | #include "pico/platform.h" 29 | 30 | #define TMDS_QUEUE_LENGTH 8 31 | 32 | struct tmds_data3; 33 | 34 | struct tmds_data { 35 | uint32_t* ptr; 36 | size_t length; 37 | struct tmds_data3* source; 38 | }; 39 | 40 | FIFO_DEF(ffifo, struct tmds_data) 41 | 42 | struct tmds_serializer { 43 | uint dma_channels[2]; 44 | struct tmds_data3* dma_data[2]; 45 | struct ffifo queue_send; 46 | uint pio_sm; 47 | }; 48 | 49 | void tmds_serializer_init(void); 50 | void tmds_serializer_create(struct tmds_serializer* s, uint gpio_base); 51 | void tmds_serializer_wait_ready(struct tmds_serializer* s); 52 | struct tmds_data3* tmds_serializer_transfer_callback(struct tmds_serializer* s); 53 | 54 | #endif -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef UTILS_H 21 | #define UTILS_H 22 | 23 | #include "pico/stdlib.h" 24 | 25 | #define likely(x) __builtin_expect(!!(x), 1) 26 | #define unlikely(x) __builtin_expect(!!(x), 0) 27 | 28 | #define READ_BIT(x, i) (((x) & (1 << (i))) ? 1 : 0) 29 | 30 | #define CORE0_DATA __scratch_x("core0_data") 31 | #define CORE0_CODE __scratch_x("core0_code") __attribute__((optimize("Os"))) 32 | 33 | #define CORE1_DATA __scratch_y("core1_data") 34 | #define CORE1_CODE __scratch_y("core1_code") __attribute__((optimize("Os"))) 35 | 36 | static inline uint32_t next_pow2(uint32_t x) { 37 | return (x == 1) ? 1 : 1 << (32 - __builtin_clz(x - 1)); 38 | } 39 | 40 | static inline size_t min_n(size_t a, size_t b) { 41 | return a < b ? a : b; 42 | } 43 | 44 | static inline size_t max_n(size_t a, size_t b) { 45 | return a > b ? a : b; 46 | } 47 | 48 | static inline size_t clamp_n(size_t x, size_t min, size_t max) { 49 | return min_n(max_n(x, min), max); 50 | } 51 | 52 | #endif -------------------------------------------------------------------------------- /src/tmds_encode.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef TMDS_ENCODE_H 21 | #define TMDS_ENCODE_H 22 | 23 | #include 24 | #include 25 | 26 | #define DATA_ISLAND_PREAMBLE_LENGTH 8 27 | #define DATA_ISLAND_GUARD_BAND 0x4CD33 28 | 29 | #define VIDEO_DATA_PREAMBLE_LENGTH 8 30 | #define VIDEO_DATA_GUARD_BAND_0 0xb32cc 31 | #define VIDEO_DATA_GUARD_BAND_1 0x4cd33 32 | #define VIDEO_DATA_GUARD_BAND_2 0xb32cc 33 | 34 | extern uint16_t tmds_terc4_symbols[16]; 35 | extern uint32_t tmds_sync_symbols[4]; 36 | extern uint32_t tmds_symbols_cbcr[9]; 37 | 38 | void tmds_encode_init(void); 39 | void tmds_encode_setup(void); 40 | uint32_t tmds_encode_y1y2(const uint32_t* pixbuf, size_t length, 41 | uint32_t* tmds); 42 | uint32_t tmds_encode_cbcr(const uint32_t* pixbuf, size_t length, 43 | uint32_t* tmds); 44 | uint32_t tmds_sync_lookup(bool vsync, bool hsync); 45 | void tmds_encode_sync(size_t length, bool vsync, uint32_t* tmds0, 46 | uint32_t* tmds1, uint32_t* tmds2); 47 | void tmds_encode_sync_video(uint32_t* tmds0, uint32_t* tmds1, uint32_t* tmds2); 48 | 49 | #endif -------------------------------------------------------------------------------- /src/mem_pool.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include "mem_pool.h" 23 | 24 | void mem_pool_create(struct mem_pool* pool, void* (*create_obj)(void*), 25 | size_t capacity, void* user) { 26 | assert(pool && capacity > 0 && create_obj); 27 | queue_init(&pool->queue, sizeof(void*), capacity); 28 | 29 | for(size_t k = 0; k < capacity; k++) { 30 | void* obj = create_obj(user); 31 | queue_add_blocking(&pool->queue, &obj); 32 | } 33 | } 34 | 35 | void* mem_pool_try_alloc(struct mem_pool* pool) { 36 | assert(pool); 37 | 38 | void* res; 39 | return queue_try_remove(&pool->queue, &res) ? res : NULL; 40 | } 41 | 42 | void* mem_pool_alloc(struct mem_pool* pool) { 43 | assert(pool); 44 | 45 | void* res; 46 | queue_remove_blocking(&pool->queue, &res); 47 | return res; 48 | } 49 | 50 | void mem_pool_free(struct mem_pool* pool, void* obj) { 51 | assert(pool && obj); 52 | // cannot fail, because queue always has enough space to store an element 53 | queue_try_add(&pool->queue, &obj); 54 | } 55 | 56 | size_t mem_pool_capacity(struct mem_pool* pool) { 57 | assert(pool); 58 | return pool->queue.element_count; 59 | } 60 | 61 | bool mem_pool_any_allocated(struct mem_pool* pool) { 62 | assert(pool); 63 | return !queue_is_full(&pool->queue); 64 | } -------------------------------------------------------------------------------- /src/mem_pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef MEM_POOL_H 21 | #define MEM_POOL_H 22 | 23 | #include "pico/util/queue.h" 24 | 25 | /** 26 | * A thread-safe memory pool. 27 | */ 28 | struct mem_pool { 29 | queue_t queue; 30 | }; 31 | 32 | /** 33 | * Creates a memory pool of given capacity, \p create_obj is called for 34 | * every object once. 35 | * 36 | * @param pool memory pool object 37 | * @param create_obj function called to initialize every object 38 | * @param capacity number of object to allocate 39 | * @param user optional pointer passed to \p create_obj 40 | */ 41 | void mem_pool_create(struct mem_pool* pool, void* (*create_obj)(void*), 42 | size_t capacity, void* user); 43 | 44 | /** 45 | * Allocates an object or returns `NULL` if none is available at this moment. 46 | * 47 | * @param pool memory pool object 48 | * @return pointer to an available object 49 | */ 50 | void* mem_pool_try_alloc(struct mem_pool* pool); 51 | 52 | /** 53 | * Blocks the current thread until an object is available. 54 | * 55 | * @param pool memory pool object 56 | * @return pointer to an available object 57 | */ 58 | void* mem_pool_alloc(struct mem_pool* pool); 59 | 60 | /** 61 | * Frees an object owned by this memory pool. Never blocks. 62 | * 63 | * @param pool memory pool object 64 | * @param obj pointer to an object 65 | */ 66 | void mem_pool_free(struct mem_pool* pool, void* obj); 67 | 68 | /** 69 | * Gets the maximum amount of allocated objects possible. 70 | * 71 | * @param pool memory pool object 72 | * @return capacity of the memory pool 73 | */ 74 | size_t mem_pool_capacity(struct mem_pool* pool); 75 | 76 | /** 77 | * Determines whether the pool has any allocated objects. 78 | * 79 | * @param pool memory pool object 80 | * @return whether the pool has any allocated objects 81 | */ 82 | bool mem_pool_any_allocated(struct mem_pool* pool); 83 | 84 | #endif -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE) 3 | set(CMAKE_C_FLAGS_RELEASE "-Os") 4 | add_compile_definitions( 5 | NDEBUG 6 | 7 | # boot rp2040 at 48MHz, later overclocked in main() 8 | SYS_CLK_KHZ=48000 9 | XOSC_KHZ=54000 10 | 11 | PLL_COMMON_REFDIV=1 12 | 13 | PLL_SYS_VCO_FREQ_KHZ=864000 14 | PLL_SYS_POSTDIV1=6 15 | PLL_SYS_POSTDIV2=3 16 | 17 | PLL_USB_VCO_FREQ_KHZ=864000 18 | PLL_USB_POSTDIV1=6 19 | PLL_USB_POSTDIV2=3 20 | ) 21 | add_link_options(-Wl,--print-memory-usage) 22 | 23 | # Pull in SDK (must be before project) 24 | set(SKIP_HARDWARE_XOSC 1) 25 | include(pico_sdk_import.cmake) 26 | 27 | project(picoave C CXX ASM) 28 | set(CMAKE_C_STANDARD 11) 29 | 30 | pico_sdk_init() 31 | 32 | unset(SKIP_HARDWARE_XOSC) 33 | pico_add_subdirectory(hardware_xosc) 34 | 35 | add_executable(picoave 36 | src/main.c 37 | src/packets.c 38 | src/packet_info_frame.c 39 | src/video_output.c 40 | src/tmds_clock.c 41 | src/tmds_serializer.c 42 | src/tmds_encode.c 43 | src/gpu_input.c 44 | src/mem_pool.c 45 | src/font.c 46 | src/str_builder.c 47 | ) 48 | 49 | pico_generate_pio_header(picoave ${CMAKE_CURRENT_LIST_DIR}/src/pio/clock.pio) 50 | pico_generate_pio_header(picoave ${CMAKE_CURRENT_LIST_DIR}/src/pio/serializer.pio) 51 | pico_generate_pio_header(picoave ${CMAKE_CURRENT_LIST_DIR}/src/pio/capture.pio) 52 | pico_generate_pio_header(picoave ${CMAKE_CURRENT_LIST_DIR}/src/pio/i2s.pio) 53 | 54 | execute_process( 55 | COMMAND git log -1 --format=%h 56 | WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} 57 | OUTPUT_VARIABLE GIT_COMMIT_HASH 58 | OUTPUT_STRIP_TRAILING_WHITESPACE 59 | ) 60 | 61 | target_compile_definitions(picoave PRIVATE 62 | PICO_STACK_SIZE=512 63 | GIT_COMMIT_HASH="${GIT_COMMIT_HASH}" 64 | ) 65 | 66 | target_compile_options(picoave PUBLIC 67 | ### Gnu/Clang C Options 68 | $<$:-fdiagnostics-color=always> 69 | $<$:-fcolor-diagnostics> 70 | 71 | $<$:-Wall> 72 | $<$:-Wextra> 73 | $<$:-Weverything> 74 | ) 75 | 76 | target_include_directories(picoave PRIVATE 77 | ${CMAKE_CURRENT_LIST_DIR} 78 | ${CMAKE_CURRENT_LIST_DIR}/../../../../Common/include 79 | ) 80 | 81 | target_link_libraries(picoave 82 | pico_multicore 83 | pico_stdlib 84 | hardware_dma 85 | hardware_irq 86 | hardware_pio 87 | hardware_interp 88 | ) 89 | 90 | pico_add_extra_outputs(picoave) 91 | 92 | pico_enable_stdio_usb(picoave 0) 93 | pico_enable_stdio_uart(picoave 0) 94 | 95 | pico_set_binary_type(picoave default) 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # picoAVE 2 | 3 | A hardware/software HDMI mod designed for the Nintendo Wii based on the rp2040 microcontroller found on a Raspberry Pi Pico. Due to the readily available parts, this mod should be a lot cheaper to build compared to FPGA based solutions. It cost me less than 50€ to have two made, so only 25€ a piece. Sadly custom PCBs are necessary, as a stock pico board does not bring out the required clock input pin and is also too large to install inplace. 4 | 5 | The CPU runs a parallel video processing pipeline across both cores to achieve full 720x480p 60Hz throughput without any color/information loss or other compromises. There is vsync by design, so tearing is impossible. A separate background task sends out audio packets in spare time. 6 | 7 | > **[Look here](docs/impl_details.md) for in-depth implementation details.** 8 | 9 | > [!NOTE] 10 | > In theory this mod should also work on a Gamecube, however I have not tested it. 11 | 12 | > [!WARNING] 13 | > Currently the only supported mode is "EDTV / HDTV (480p)" as found in Wii settings. 14 | > Any other mode results in no signal output! 15 | 16 | ## Building (software) 17 | 18 | This is the same as any other pico project. You should probably edit the pico sdk path, too. It is absolutely crucial to build in release mode. Firmware flashing is covered [here](docs/building_hardware.md#flashing-firmware). 19 | 20 | ```bash 21 | mkdir build 22 | cd build 23 | cmake -DCMAKE_BUILD_TYPE=Release -DPICO_SDK_PATH=/opt/pico-sdk/ .. 24 | make 25 | ``` 26 | 27 | ## Building (hardware) 28 | 29 | > **[Look here](docs/building_hardware.md) for instructions.** 30 | 31 | ## Pictures 32 | ![Wii menu frame](docs/images/frame.png) 33 | > Example raw frame captured from the Wii home menu with a cheap HDMI capture card. There is a small overlay with information about the current input signal, which disappears after a few seconds. Note, that the native aspect ratio is not 16:9. 34 | 35 | ![picoAVE rev01](docs/images/finished_install.webp) 36 | > The first hardware revision, designed to solder directly onto a prototype flex pcb. The main pcb contains a rp2040, voltage level shifter, flash memory and LDO regulator. There is a second pcb for the HDMI mini output, connected by a 16 pin FFC. Wires are needed for GND, 5V, 1.8V and CLK connections. Firmware is flashed over a SWD header on the bottom left. 37 | 38 | ![Original prototype](docs/images/prototype.webp) 39 | > The original prototype, still based on an actual pico board. Because the CPU clock ran unsynchronized to the video input, the HDMI signal dropped every few seconds (pipeline ran out of data). There are two TXS0108E voltage shifters to adapt the 1.8V signal levels of the GPU to 3.3V of a pico. Below is a custom flex pcb soldered directly to the board's vias. The Wii2HDMI is only used to force the Wii into 480p output mode. Original [Reddit post](https://www.reddit.com/r/wii/comments/1d0bm9p/picoave_a_new_wii_hdmi_mod_i_am_working_on/). 40 | -------------------------------------------------------------------------------- /pico_sdk_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /external/pico_sdk_import.cmake 2 | 3 | # This can be dropped into an external project to help locate this SDK 4 | # It should be include()ed prior to project() 5 | 6 | if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) 7 | set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) 8 | message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") 9 | endif () 10 | 11 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) 12 | set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) 13 | message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") 14 | endif () 15 | 16 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) 17 | set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) 18 | message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") 19 | endif () 20 | 21 | set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 22 | set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable") 23 | set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") 24 | 25 | if (NOT PICO_SDK_PATH) 26 | if (PICO_SDK_FETCH_FROM_GIT) 27 | include(FetchContent) 28 | set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) 29 | if (PICO_SDK_FETCH_FROM_GIT_PATH) 30 | get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") 31 | endif () 32 | FetchContent_Declare( 33 | pico_sdk 34 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 35 | GIT_TAG master 36 | ) 37 | if (NOT pico_sdk) 38 | message("Downloading Raspberry Pi Pico SDK") 39 | FetchContent_Populate(pico_sdk) 40 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) 41 | endif () 42 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) 43 | else () 44 | message(FATAL_ERROR 45 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." 46 | ) 47 | endif () 48 | endif () 49 | 50 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 51 | if (NOT EXISTS ${PICO_SDK_PATH}) 52 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") 53 | endif () 54 | 55 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) 56 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) 57 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") 58 | endif () 59 | 60 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) 61 | 62 | include(${PICO_SDK_INIT_CMAKE_FILE}) 63 | -------------------------------------------------------------------------------- /src/packet_info_frame.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include "packet_info_frame.h" 23 | 24 | static void apply_checksum(struct packet* p) { 25 | uint8_t sum = 0; 26 | 27 | for(size_t k = 0; k < sizeof(p->header) - 1; k++) 28 | sum += p->header[k]; 29 | 30 | for(size_t k = 0; k < sizeof(p->data); k++) { 31 | if(k % 8 != 7) 32 | sum += p->data[k]; 33 | } 34 | 35 | p->data[0] = -sum; 36 | } 37 | 38 | void packet_avi_info(struct packet* p) { 39 | memset(p->header, 0, sizeof(p->header)); 40 | memset(p->data, 0, sizeof(p->data)); 41 | 42 | p->header[0] = 0x82; 43 | p->header[1] = 0x02; 44 | p->header[2] = 13; 45 | 46 | p->data[1] = 0b00100010; 47 | p->data[2] = 0b01101000; 48 | p->data[4] = 3; 49 | 50 | apply_checksum(p); 51 | } 52 | 53 | // vendor max 8 54 | // product max 16 55 | void packet_spd_info(struct packet* p, const char* vendor, 56 | const char* product) { 57 | memset(p->header, 0, sizeof(p->header)); 58 | memset(p->data, 0, sizeof(p->data)); 59 | 60 | p->header[0] = 0x83; 61 | p->header[1] = 0x01; 62 | p->header[2] = 25; 63 | 64 | strncpy((char*)p->data + 1, vendor, 8); 65 | strncpy((char*)p->data + 10, product, 16); 66 | p->data[28] = 0x08; // game 67 | 68 | apply_checksum(p); 69 | } 70 | 71 | void packet_audio_info(struct packet* p, size_t samplerate) { 72 | memset(p->header, 0, sizeof(p->header)); 73 | memset(p->data, 0, sizeof(p->data)); 74 | 75 | p->header[0] = 0x84; 76 | p->header[1] = 0x01; 77 | p->header[2] = 10; 78 | 79 | p->data[1] = 1 | (1 << 4); 80 | p->data[2] = 1 | (samplerate << 2); 81 | p->data[4] = 0; 82 | p->data[5] = (0 << 3) | (0 << 7); 83 | 84 | apply_checksum(p); 85 | } 86 | 87 | void packet_audio_clk_regen(struct packet* p, uint32_t n, uint32_t cts) { 88 | p->header[0] = 0x01; 89 | p->header[1] = 0x00; 90 | p->header[2] = 0x00; 91 | 92 | for(size_t k = 0; k < PACKET_BODY_LENGTH; k += PACKET_SUBLANE_LENGTH) { 93 | p->data[k + 0] = 0; 94 | p->data[k + 1] = (cts >> 16) & 0xFF; 95 | p->data[k + 2] = (cts >> 8) & 0xFF; 96 | p->data[k + 3] = cts & 0xFF; 97 | p->data[k + 4] = (n >> 16) & 0xFF; 98 | p->data[k + 5] = (n >> 8) & 0xFF; 99 | p->data[k + 6] = n & 0xFF; 100 | } 101 | } -------------------------------------------------------------------------------- /hardware/hdmi_pcb/wii_hdmi_pcb.kicad_dru: -------------------------------------------------------------------------------- 1 | (version 1) 2 | #Kicad 7 3 | 4 | # 2-layer, 1oz copper 5 | (rule "Minimum Trace Width (outer layer)" 6 | (constraint track_width (min 5mil)) 7 | (layer outer) 8 | (condition "A.Type == 'track'")) 9 | 10 | (rule "Minimum Trace Spacing (outer layer)" 11 | (constraint clearance (min 5mil)) 12 | (layer outer) 13 | (condition "A.Type == 'track' && B.Type == A.Type")) 14 | 15 | # 4-layer 16 | (rule "Minimum Trace Width and Spacing (inner layer)" 17 | (constraint track_width (min 3.5mil)) 18 | (layer inner) 19 | (condition "A.Type == 'track'")) 20 | 21 | (rule "Minimum Trace Spacing (inner layer)" 22 | (constraint clearance (min 3.5mil)) 23 | (layer inner) 24 | (condition "A.Type == 'track' && B.Type == A.Type")) 25 | 26 | # silkscreen (Kicad 7 only) 27 | (rule "Minimum Text" 28 | (constraint text_thickness (min 0.15mm)) 29 | (constraint text_height (min 1mm)) 30 | (layer "?.Silkscreen")) 31 | 32 | (rule "Pad to Silkscreen" 33 | (constraint silk_clearance (min 0.15mm)) 34 | (layer outer) 35 | (condition "A.Type == 'pad' && (B.Type == 'text' || B.Type == 'graphic')")) 36 | 37 | # edge clearance 38 | (rule "Trace to Outline" 39 | (constraint edge_clearance (min 0.3mm)) 40 | (condition "A.Type == 'track'")) 41 | 42 | # This would override board outline and milled areas 43 | #(rule "Trace to V-Cut" 44 | # (constraint clearance (min 0.4mm)) 45 | # (condition "A.Type == 'track' && B.Layer == 'Edge.Cuts'")) 46 | 47 | # drill/hole size 48 | (rule "drill hole size (mechanical)" 49 | (constraint hole_size (min 0.2mm) (max 6.3mm))) 50 | 51 | (rule "Minimum Via Hole Size" 52 | (constraint hole_size (min 0.2mm)) 53 | (condition "A.Type == 'via'")) 54 | 55 | (rule "Minimum Via Diameter" 56 | (constraint via_diameter (min 0.45mm)) 57 | (condition "A.Type == 'via'")) 58 | 59 | (rule "PTH Hole Size" 60 | (constraint hole_size (min 0.2mm) (max 6.35mm)) 61 | (condition "A.isPlated()")) 62 | 63 | (rule "Minimum Non-plated Hole Size" 64 | (constraint hole_size (min 0.5mm)) 65 | (condition "A.Type == 'pad' && !A.isPlated()")) 66 | 67 | (rule "Minimum Castellated Hole Size" 68 | (constraint hole_size (min 0.6mm)) 69 | (condition "A.Type == 'pad' && A.Fabrication_Property == 'Castellated pad'")) 70 | 71 | # clearance 72 | (rule "hole to hole clearance (different nets)" 73 | (constraint hole_to_hole (min 0.5mm)) 74 | (condition "A.Net != B.Net")) 75 | 76 | (rule "via to track clearance" 77 | (constraint hole_clearance (min 0.254mm)) 78 | (condition "A.Type == 'via' && B.Type == 'track'")) 79 | 80 | (rule "via to via clearance (same nets)" 81 | (constraint hole_to_hole (min 0.254mm)) 82 | (condition "A.Type == 'via' && B.Type == A.Type && A.Net == B.Net")) 83 | 84 | (rule "pad to pad clearance (with hole, different nets)" 85 | (constraint hole_to_hole (min 0.5mm)) 86 | (condition "A.Type == 'pad' && B.Type == A.Type && A.Net != B.Net")) 87 | 88 | (rule "pad to pad clearance (without hole, different nets)" 89 | (constraint clearance (min 0.127mm)) 90 | (condition "A.Type == 'pad' && B.Type == A.Type && A.Net != B.Net")) 91 | 92 | (rule "NPTH to Track clearance)" 93 | (constraint hole_clearance (min 0.254mm)) 94 | (condition "A.Pad_Type == 'NPTH, mechanical' && B.Type == 'track'")) 95 | 96 | (rule "PTH to Track clearance)" 97 | (constraint hole_clearance (min 0.33mm)) 98 | (condition "A.isPlated() && B.Type == 'track'")) 99 | 100 | (rule "Pad to Track clearance)" 101 | (constraint clearance (min 0.2mm)) 102 | (condition "A.isPlated() && B.Type == 'track'")) 103 | -------------------------------------------------------------------------------- /hardware/wii_mainboard/wii_mainboard.kicad_dru: -------------------------------------------------------------------------------- 1 | (version 1) 2 | #Kicad 7 3 | 4 | # 2-layer, 1oz copper 5 | (rule "Minimum Trace Width (outer layer)" 6 | (constraint track_width (min 5mil)) 7 | (layer outer) 8 | (condition "A.Type == 'track'")) 9 | 10 | (rule "Minimum Trace Spacing (outer layer)" 11 | (constraint clearance (min 5mil)) 12 | (layer outer) 13 | (condition "A.Type == 'track' && B.Type == A.Type")) 14 | 15 | # 4-layer 16 | (rule "Minimum Trace Width and Spacing (inner layer)" 17 | (constraint track_width (min 3.5mil)) 18 | (layer inner) 19 | (condition "A.Type == 'track'")) 20 | 21 | (rule "Minimum Trace Spacing (inner layer)" 22 | (constraint clearance (min 3.5mil)) 23 | (layer inner) 24 | (condition "A.Type == 'track' && B.Type == A.Type")) 25 | 26 | # silkscreen (Kicad 7 only) 27 | (rule "Minimum Text" 28 | (constraint text_thickness (min 0.15mm)) 29 | (constraint text_height (min 1mm)) 30 | (layer "?.Silkscreen")) 31 | 32 | (rule "Pad to Silkscreen" 33 | (constraint silk_clearance (min 0.15mm)) 34 | (layer outer) 35 | (condition "A.Type == 'pad' && (B.Type == 'text' || B.Type == 'graphic')")) 36 | 37 | # edge clearance 38 | (rule "Trace to Outline" 39 | (constraint edge_clearance (min 0.3mm)) 40 | (condition "A.Type == 'track'")) 41 | 42 | # This would override board outline and milled areas 43 | #(rule "Trace to V-Cut" 44 | # (constraint clearance (min 0.4mm)) 45 | # (condition "A.Type == 'track' && B.Layer == 'Edge.Cuts'")) 46 | 47 | # drill/hole size 48 | (rule "drill hole size (mechanical)" 49 | (constraint hole_size (min 0.2mm) (max 6.3mm))) 50 | 51 | (rule "Minimum Via Hole Size" 52 | (constraint hole_size (min 0.2mm)) 53 | (condition "A.Type == 'via'")) 54 | 55 | (rule "Minimum Via Diameter" 56 | (constraint via_diameter (min 0.45mm)) 57 | (condition "A.Type == 'via'")) 58 | 59 | (rule "PTH Hole Size" 60 | (constraint hole_size (min 0.2mm) (max 6.35mm)) 61 | (condition "A.isPlated()")) 62 | 63 | (rule "Minimum Non-plated Hole Size" 64 | (constraint hole_size (min 0.5mm)) 65 | (condition "A.Type == 'pad' && !A.isPlated()")) 66 | 67 | (rule "Minimum Castellated Hole Size" 68 | (constraint hole_size (min 0.6mm)) 69 | (condition "A.Type == 'pad' && A.Fabrication_Property == 'Castellated pad'")) 70 | 71 | # clearance 72 | (rule "hole to hole clearance (different nets)" 73 | (constraint hole_to_hole (min 0.5mm)) 74 | (condition "A.Net != B.Net")) 75 | 76 | (rule "via to track clearance" 77 | (constraint hole_clearance (min 0.254mm)) 78 | (condition "A.Type == 'via' && B.Type == 'track'")) 79 | 80 | (rule "via to via clearance (same nets)" 81 | (constraint hole_to_hole (min 0.254mm)) 82 | (condition "A.Type == 'via' && B.Type == A.Type && A.Net == B.Net")) 83 | 84 | (rule "pad to pad clearance (with hole, different nets)" 85 | (constraint hole_to_hole (min 0.5mm)) 86 | (condition "A.Type == 'pad' && B.Type == A.Type && A.Net != B.Net")) 87 | 88 | (rule "pad to pad clearance (without hole, different nets)" 89 | (constraint clearance (min 0.127mm)) 90 | (condition "A.Type == 'pad' && B.Type == A.Type && A.Net != B.Net")) 91 | 92 | (rule "NPTH to Track clearance)" 93 | (constraint hole_clearance (min 0.254mm)) 94 | (condition "A.Pad_Type == 'NPTH, mechanical' && B.Type == 'track'")) 95 | 96 | (rule "PTH to Track clearance)" 97 | (constraint hole_clearance (min 0.33mm)) 98 | (condition "A.isPlated() && B.Type == 'track'")) 99 | 100 | (rule "Pad to Track clearance)" 101 | (constraint clearance (min 0.2mm)) 102 | (condition "A.isPlated() && B.Type == 'track'")) 103 | -------------------------------------------------------------------------------- /docs/building_hardware.md: -------------------------------------------------------------------------------- 1 | ## Required parts 2 | 3 | * picoAVE mainboard 4 |
5 | * HDMI adapter board 6 |
7 | * Bridge flex pcb (orange) 8 | * FFC flex cable 9 | * 10cm (3.9in) is fine, but preferably shorter. I guess 7cm (2.75in) would fit best if you can source one (untested). 10 | * 16 pin 11 | * 0.5mm pitch 12 | * ends need their pins on opposite sides (there is a 90° bend during install) 13 | 14 | #### Ordering 15 | 16 | All PCBs were designed to be ordered easily and for cheap at JLCPCB. The KiCAD project files for each PCB can be found in `hardware/.../`. The following instructions need to be done for all 3 of them. Use the [Fabrication Toolkit plugin](https://github.com/bennymeg/Fabrication-Toolkit) to export all required files to a subfolder called `hardware/.../production/`. Start with the generated zip file and upload it to their ordering page. 17 | 18 | For the main and HDMI adapter board make sure to select the following options: 19 | * PCB thickness: 0.8mm 20 | * Mark on PCB: Order Number (specify position) 21 | 22 | Then: 23 | * Activate the PCB assembly slider (in case it asks: you don't need panelization) 24 | * Make sure to use economic assembly 25 | * Assemble top side 26 | * Select a quantity of 27 | * 2 for the mainboard 28 | * 5 for the adapter board, which I highly recommend as it does cost less than 1€ to order these 3 additional boards and I already had a defect in 1 out of 5 boards (HDMI connector pins shorted) 29 | 30 | Furher on you need to upload the generated `bom.csv` and `positions.csv`. 31 | 32 | Later during checkout make sure to have the SMT assembly coupon activated, you might need to redeem it first on their coupon center page in case it is missing. Sadly you have to pass checkout seperately for each PCB, because you can only apply one coupon at a time. 33 | 34 | For the bridge flex pcb, select: 35 | * Base material: flex 36 | * Mark on PCB: Order Number (specify position) 37 | 38 | ## Assembly steps 39 | 40 | #### Mainboard + Bridge pcb 41 | 1. Solder the bridge pcb onto the back of the picoAVE mainboard. 42 | 2. Remove the solder mask from necessary vias on the Wii mainboard. A tiny flat head screw driver can be used to just scrape it off and works well. **Be gentle and use almost no pressue!** Make sure to remove accumulated dust. 43 | 3. Apply flux to the now exposed vias. 44 | 4. Apply solder to the tip of your iron and attach a small ball of solder onto each via. Make sure there are no shorts/bridges. If it won't stick, try scraping more. 45 | 5. Place and align the bridge pcb onto the solder balls. Then apply solder over all holes evenly until the pcb is firmly pulled towards the Wii mainboard. There must not be a gap between both pcbs. Again, make sure there are no bridges. 46 | 6. For each signal, check for continuity between the picoAVE mainboard and corresponding pins on the AVE-RVL chip to ensure good contact. 47 | 48 | ## Flashing firmware 49 | 50 | Best done with a Raspberry Pi or another Pico you have available. 51 | 52 | With a Raspberry Pi you can use [OpenOCD](https://openocd.org/) to flash the main board over SWD using two GPIO pins, e.g. 23 and 24. The following config should be saved as `openocd.cfg`. 53 | 54 | ```ini 55 | source [find interface/raspberrypi-native.cfg] 56 | 57 | adapter gpio swclk 23 58 | adapter gpio swdio 24 59 | 60 | set CHIPNAME rp2040 61 | source [find target/rp2040.cfg] 62 | adapter speed 100 63 | 64 | init 65 | targets 66 | reset halt 67 | program picoave.elf verify 68 | reset run 69 | shutdown 70 | ``` 71 | 72 | OpenOCD can then be started by `sudo openocd` in the same directory. Flashing will only take a few seconds. 73 | 74 | ### Connections 75 | 76 | | Signal | RPi Pin | 77 | | ------ | :-----: | 78 | | SWCLK | 23 | 79 | | SWDIO | 24 | 80 | | GND | any GND | -------------------------------------------------------------------------------- /src/tmds_serializer.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "hardware/dma.h" 24 | #include "hardware/irq.h" 25 | #include "pico/platform.h" 26 | #include "pico/stdlib.h" 27 | #include "utils.h" 28 | 29 | #include "serializer.pio.h" 30 | #include "tmds_serializer.h" 31 | 32 | static uint pio_program_offset; 33 | 34 | #define DUMMY_DATA_LENGTH 1024 35 | static uint32_t dummy_data = 0xFF; 36 | 37 | static void dma_tmds_configure(uint channel, uint other_channel, uint sm) { 38 | assert(channel != other_channel); 39 | 40 | dma_channel_config c = dma_channel_get_default_config(channel); 41 | channel_config_set_transfer_data_size(&c, DMA_SIZE_32); 42 | channel_config_set_chain_to(&c, other_channel); 43 | channel_config_set_dreq(&c, pio_get_dreq(pio0, sm, true)); 44 | channel_config_set_read_increment(&c, true); 45 | channel_config_set_write_increment(&c, false); 46 | dma_channel_configure(channel, &c, &pio0->txf[sm], &dummy_data, 47 | DUMMY_DATA_LENGTH, false); 48 | dma_channel_set_irq0_enabled(channel, true); 49 | } 50 | 51 | struct tmds_data3* CORE0_CODE 52 | tmds_serializer_transfer_callback(struct tmds_serializer* s) { 53 | for(size_t k = 0; k < 2; k++) { 54 | if(dma_channel_get_irq0_status(s->dma_channels[k])) { 55 | dma_channel_acknowledge_irq0(s->dma_channels[k]); 56 | 57 | struct tmds_data3* completed = s->dma_data[k]; 58 | 59 | struct tmds_data data; 60 | if(likely(ffifo_pop(&s->queue_send, &data))) { 61 | dma_channel_config c 62 | = dma_get_channel_config(s->dma_channels[k]); 63 | channel_config_set_read_increment(&c, data.ptr != &dummy_data); 64 | dma_channel_set_config(s->dma_channels[k], &c, false); 65 | 66 | dma_channel_set_read_addr(s->dma_channels[k], data.ptr, false); 67 | dma_channel_set_trans_count(s->dma_channels[k], data.length, 68 | false); 69 | s->dma_data[k] = data.source; 70 | } else { 71 | panic_unsupported(); 72 | } 73 | 74 | return completed; 75 | } 76 | } 77 | 78 | return NULL; 79 | } 80 | 81 | void tmds_serializer_init() { 82 | pio_program_offset = pio_add_program(pio0, &pio_serializer_program); 83 | } 84 | 85 | void tmds_serializer_create(struct tmds_serializer* s, uint gpio_base) { 86 | assert(s && gpio_base < 32 && (gpio_base % 2) == 0); 87 | 88 | s->pio_sm = pio_claim_unused_sm(pio0, true); 89 | pio_serializer_program_init(pio0, s->pio_sm, pio_program_offset, gpio_base); 90 | 91 | ffifo_init(&s->queue_send, TMDS_QUEUE_LENGTH); 92 | 93 | while(!ffifo_full(&s->queue_send)) { 94 | ffifo_push(&s->queue_send, 95 | &(struct tmds_data) { 96 | .ptr = &dummy_data, 97 | .length = DUMMY_DATA_LENGTH, 98 | .source = NULL, 99 | }); 100 | } 101 | 102 | for(size_t k = 0; k < 2; k++) { 103 | s->dma_channels[k] = dma_claim_unused_channel(true); 104 | s->dma_data[k] = NULL; 105 | } 106 | 107 | dma_tmds_configure(s->dma_channels[0], s->dma_channels[1], s->pio_sm); 108 | dma_tmds_configure(s->dma_channels[1], s->dma_channels[0], s->pio_sm); 109 | dma_channel_start(s->dma_channels[0]); 110 | } 111 | 112 | void tmds_serializer_wait_ready(struct tmds_serializer* s) { 113 | while(!pio_sm_is_tx_fifo_full(pio0, s->pio_sm)) 114 | tight_loop_contents(); 115 | } -------------------------------------------------------------------------------- /docs/impl_details.md: -------------------------------------------------------------------------------- 1 | ## Processing pipeline 2 | #### Video 3 | 1. A PIO captures the [incoming video signal](https://wiibrew.org/wiki/Hardware/AV_Encoder#VData_Encoding) from the AV Encoder, which encodes a frame in NTSC timing and Ycbcr color space. There is a continous DMA transfer with two channels running as a ping-pong configuration. On completion of each transfer, its data buffer is put in a queue for later processing. 4 | 2. Core 2 recieves completed buffers filled with video data from this queue. Every visible display region is copied from a buffer and the cbcr-data is TMDS encoded. A pre-sync step (run once in advance) determines which data regions are visible video data and need to be extracted. Once one display line is finished, it is sent to core 1 using another queue. 5 | 3. Core 1 takes each display line and encodes the missing y1y2-data; the result is placed into a final queue. This step runs at highest priority using a software-triggered interrupt, initiated by core 2. 6 | 4. At last there are 3 PIOs, each encoding one differential signal lane, and are supplied by 3 DMA transfers on ping-pong buffers. A DMA completion interrupt builds the HDMI signal at run time; placing display lines and data packets as needed. 7 | 8 | #### Audio 9 | The processing is similar to video, except that solely core 1 encodes incoming audio frames to HDMI data packets at a lower priority. 10 | 11 | ## TMDS encoding 12 | 13 | Video data is arranged as 32-bit words, each containing 2 pixels as `(y1, cb, y2, cr)` tuples (Ycbcr color space, each element 8-bits). Encoding is a two step process, first `tmds_encode_y1y2()` encodes `(y1, y2)` into one TMDS-lane, then `tmds_encode_cbcr()` the color part `(cb, cr)` separately. For cbcr it simply shifts the input data before processing, but then continues exactly the same. Both implementations are unrolled to process 6 pixels at once, so necessary loads and stores can be combined to save cycles. The (assembly) code can be found in [`tmds_encode.c`](../src/tmds_encode.c). 14 | 15 | #### TMDS LUTs 16 | There are two lookup tables (LUT) for TMDS generation. Each table contains 32-bit words of `(bias, symbol)`. The (following) bias consists of 4-bits stored in the MSBs, as TMDS encoding only ever uses 9 different bias values. Each lookup requires a pixel value and the preceding bias as address, then giving the following bias and TMDS encoded symbol. The symbol is either stored at bit offset 0 or 10 depending on the lookup table. The idea is that LUT 1 contains the first pixel and LUT 2 the second. Because the differential output stage (realized by a PIO) requires a sequential stream of bits on the lower 20-bits of each word, the words from both LUTs can then be simply OR-ed together to receive the final output for both pixels. Both lanes of an interpolator are used to compute the lookup addresses. 17 | 18 | #### Interpolator configuration 19 | 20 | The interpolator receives a pixel pair `(y1, cb, y2, cr)`. 21 | 22 | * Lane 0 extracts y2 and shifts and masks that 8-bit part into bits `[9:2]`. Finally the LUT 1 address is added. LUT 1 is indexed by `bias * 256 + y2`. 23 | * Lane 1 extracts y1 and moves those to bits `[13:6]`, then the LUT 2 base address is added. LUT 2 is indexed by `y1 * 16 + bias`. 24 | 25 | Note, how both lanes are different, especially in their memory layout. Ideally both LUTs would use the memory layout of LUT 1, because it wastes no space (remember only 9 of 16 biases are used) and distributes loads across all four SRAM banks evenly, however the layout of each LUT word `(bias, symbol)` prevents this: To save cycles the bias is added onto the interpolator output by the memory load operation itself, as in the following example. 26 | 27 | ```arm 28 | ldr %%r7, [%[interp], #0x24] // get result from interpolator 29 | ldr %%r7, [%%r7, %[bias]] // load from lookup table 30 | ``` 31 | 32 | The bias offset needs to be naturally aligned (4 bytes) and is right shifted after each lookup from the MSBs down to the correct position, for the final address addition. Thus in layout of LUT 1 we need at least 10 empty padding (0) bits between bias and symbol in a LUT word (8 for `bias * 256` and 2 for alignment). This is fine for the layout of the first pixel `(bias, 18, symbol)`, but is an issue with `(bias, 8, symbol, 10)` of the second pixel, which would then violate natural alignment, because of garbage data in the lowest 2 bits (masking these would require another cycle which should be avoided). 33 | 34 | #### Processing steps 35 | 36 | 1. The pixel pair is sent to the interpolator. 37 | 2. The first pixel base offset is retrieved, then the LUT 1 word is loaded from this offset and the current bias. 38 | 3. The current bias is updated by extracting the "following" bias from the LUT word. It is shifted to the right position for the next lookup. 39 | 4. The second pixel base offset is retrieved, then the LUT 2 word is loaded from this offset and the current bias. 40 | 5. The current bias is updated as before. 41 | 6. Both LUT words are OR-ed together to receive the final output. -------------------------------------------------------------------------------- /src/packets.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "packets.h" 28 | #include "pico/stdlib.h" 29 | #include "tmds_encode.h" 30 | #include "utils.h" 31 | 32 | static uint32_t CORE0_DATA tmds_terc4_symbols2[256]; 33 | static uint8_t CORE0_DATA bch_lookup[256]; 34 | static uint32_t sub_lookup[256]; 35 | static uint8_t CORE0_DATA parity_lookup[256]; 36 | static uint32_t header_lookup[256]; 37 | 38 | static uint8_t bch_gen(uint8_t in) { 39 | uint8_t state = 0; 40 | 41 | for(size_t i = 0; i < 8; i++) { 42 | uint8_t feedback = (state ^ in) & 0x01; 43 | in >>= 1; 44 | 45 | uint8_t p0 = ((state & 0x02) ^ (feedback << 1)) >> 1; 46 | uint8_t p1 = ((state & 0x04) ^ (feedback << 2)) >> 1; 47 | uint8_t p2 = (state & 0xF8) >> 1; 48 | uint8_t p3 = feedback << 7; 49 | 50 | state = p0 | p1 | p2 | p3; 51 | } 52 | 53 | return state; 54 | } 55 | 56 | static uint8_t bch_calc(uint8_t* data, size_t length) { 57 | uint8_t state = 0; 58 | 59 | for(size_t k = 0; k < length; k++) 60 | state = bch_lookup[data[k] ^ state]; 61 | 62 | return state; 63 | } 64 | 65 | void packets_init() { 66 | for(size_t k = 0; k < 256; k++) { 67 | bch_lookup[k] = bch_gen(k); 68 | parity_lookup[k] = __builtin_parity(k); 69 | 70 | header_lookup[k] = (READ_BIT(k, 7) << 30) | (READ_BIT(k, 6) << 26) 71 | | (READ_BIT(k, 5) << 22) | (READ_BIT(k, 4) << 18) 72 | | (READ_BIT(k, 3) << 14) | (READ_BIT(k, 2) << 10) 73 | | (READ_BIT(k, 1) << 6) | (READ_BIT(k, 0) << 2); 74 | 75 | sub_lookup[k] = (READ_BIT(k, 7) << 28) | (READ_BIT(k, 5) << 24) 76 | | (READ_BIT(k, 3) << 20) | (READ_BIT(k, 1) << 16) 77 | | (READ_BIT(k, 6) << 12) | (READ_BIT(k, 4) << 8) 78 | | (READ_BIT(k, 2) << 4) | READ_BIT(k, 0); 79 | } 80 | 81 | for(size_t k = 0; k < 16; k++) { 82 | for(size_t i = 0; i < 16; i++) { 83 | tmds_terc4_symbols2[(k << 4) | i] 84 | = (tmds_terc4_symbols[k] << 10) | tmds_terc4_symbols[i]; 85 | } 86 | } 87 | } 88 | 89 | static void encode_header(uint8_t* data, uint32_t* tmds0, bool hsync, 90 | bool vsync, bool first_packet) { 91 | size_t pos = 0; 92 | uint32_t sync32 93 | = __mul_instruction(0x11111111, 0x08 | (vsync << 1) | hsync); 94 | uint32_t sync32_f = sync32 & 0xFFFFFFF7; 95 | 96 | for(size_t k = 0; k < PACKET_HEADER_LENGTH; k++) { 97 | uint32_t sync = (k == 0 && first_packet) ? sync32_f : sync32; 98 | uint32_t res = header_lookup[data[k]] | sync; 99 | 100 | tmds0[pos++] = tmds_terc4_symbols2[res & 0xFF]; 101 | tmds0[pos++] = tmds_terc4_symbols2[(res >> 8) & 0xFF]; 102 | tmds0[pos++] = tmds_terc4_symbols2[(res >> 16) & 0xFF]; 103 | tmds0[pos++] = tmds_terc4_symbols2[res >> 24]; 104 | } 105 | } 106 | 107 | static void encode_sub_lane(uint8_t* data, uint32_t* tmds1, uint32_t* tmds2) { 108 | size_t pos = 0; 109 | 110 | for(size_t k = 0; k < PACKET_SUBLANE_LENGTH; k++) { 111 | uint32_t res = 0; 112 | 113 | for(size_t i = 0; i < 4; i++) 114 | res |= sub_lookup[data[k + i * 8]] << i; 115 | 116 | tmds1[pos + 0] = tmds_terc4_symbols2[res & 0xFF]; 117 | tmds1[pos + 1] = tmds_terc4_symbols2[(res >> 8) & 0xFF]; 118 | tmds2[pos + 0] = tmds_terc4_symbols2[(res >> 16) & 0xFF]; 119 | tmds2[pos + 1] = tmds_terc4_symbols2[res >> 24]; 120 | pos += 2; 121 | } 122 | } 123 | 124 | static void data_encode(struct packet* p, bool hsync, bool vsync, 125 | bool first_packet, uint32_t* tmds0, uint32_t* tmds1, 126 | uint32_t* tmds2) { 127 | p->header[PACKET_HEADER_LENGTH - 1] 128 | = bch_calc(p->header, PACKET_HEADER_LENGTH - 1); 129 | 130 | for(size_t k = 0; k < PACKET_SUBLANE_COUNT; k++) 131 | p->data[(k + 1) * PACKET_SUBLANE_LENGTH - 1] = bch_calc( 132 | p->data + k * PACKET_SUBLANE_LENGTH, PACKET_SUBLANE_LENGTH - 1); 133 | 134 | encode_header(p->header, tmds0, hsync, vsync, first_packet); 135 | encode_sub_lane(p->data, tmds1, tmds2); 136 | } 137 | 138 | // encode packets with constant h+vsync 139 | void packets_encode(struct packet* p, size_t amount, bool hsync, bool vsync, 140 | uint32_t* tmds0, uint32_t* tmds1, uint32_t* tmds2) { 141 | // preamble (8 pixels) 142 | for(size_t k = 0; k < DATA_ISLAND_PREAMBLE_LENGTH / 2; k++) { 143 | *(tmds0++) = tmds_sync_lookup(vsync, hsync); 144 | *(tmds1++) = tmds_sync_symbols[1]; // CTL0 = 1, CTL1 = 0 145 | *(tmds2++) = tmds_sync_symbols[1]; // CTL2 = 1, CTL3 = 0 146 | } 147 | 148 | size_t sync_state = 0x0C | (vsync << 1) | hsync; 149 | uint32_t terc4_sync = tmds_terc4_symbols2[(sync_state << 4) | sync_state]; 150 | 151 | // leading guard band (2 pixels) 152 | *(tmds0++) = terc4_sync; 153 | *(tmds1++) = DATA_ISLAND_GUARD_BAND; 154 | *(tmds2++) = DATA_ISLAND_GUARD_BAND; 155 | 156 | // data island (32 pixels * amount) 157 | for(size_t k = 0; k < amount; k++) { 158 | data_encode(p + k, hsync, vsync, k == 0, tmds0, tmds1, tmds2); 159 | tmds0 += PACKET_BODY_LENGTH / 2; 160 | tmds1 += PACKET_BODY_LENGTH / 2; 161 | tmds2 += PACKET_BODY_LENGTH / 2; 162 | } 163 | 164 | // trailing guard band (2 pixels) 165 | *(tmds0++) = terc4_sync; 166 | *(tmds1++) = DATA_ISLAND_GUARD_BAND; 167 | *(tmds2++) = DATA_ISLAND_GUARD_BAND; 168 | } 169 | 170 | // length of encoded packets in pixels 171 | size_t packets_length(size_t amount) { 172 | return amount * PACKET_BODY_LENGTH + 4 + DATA_ISLAND_PREAMBLE_LENGTH; 173 | } 174 | 175 | // encode audio with constant h+vsync 176 | void packets_encode_audio(uint32_t samples[4], size_t frame, bool hsync, 177 | bool vsync, uint32_t* tmds0, uint32_t* tmds1, 178 | uint32_t* tmds2) { 179 | // preamble (8 pixels) 180 | for(size_t k = 0; k < DATA_ISLAND_PREAMBLE_LENGTH / 2; k++) { 181 | *(tmds0++) = tmds_sync_lookup(vsync, hsync); 182 | *(tmds1++) = tmds_sync_symbols[1]; // CTL0 = 1, CTL1 = 0 183 | *(tmds2++) = tmds_sync_symbols[1]; // CTL2 = 1, CTL3 = 0 184 | } 185 | 186 | size_t sync_state = 0x0C | (vsync << 1) | hsync; 187 | uint32_t terc4_sync = tmds_terc4_symbols2[(sync_state << 4) | sync_state]; 188 | 189 | // leading guard band (2 pixels) 190 | *(tmds0++) = terc4_sync; 191 | *(tmds1++) = DATA_ISLAND_GUARD_BAND; 192 | *(tmds2++) = DATA_ISLAND_GUARD_BAND; 193 | 194 | struct packet p; 195 | p.header[0] = 0x02; 196 | p.header[1] = 0x0F; 197 | p.header[2] = (frame == 0) ? 0x10 : 0x00; 198 | 199 | for(size_t k = 0; k < PACKET_BODY_LENGTH; k += PACKET_SUBLANE_LENGTH) { 200 | uint32_t s = *(samples++); 201 | 202 | // left channel 203 | p.data[k + 0] = 0; 204 | p.data[k + 1] = (s >> 16) & 0xFF; 205 | p.data[k + 2] = s >> 24; 206 | 207 | // right channel 208 | p.data[k + 3] = 0; 209 | p.data[k + 4] = s & 0xFF; 210 | p.data[k + 5] = (s >> 8) & 0xFF; 211 | 212 | uint8_t p_left = parity_lookup[p.data[k + 1] ^ p.data[k + 2] ^ 0x01]; 213 | uint8_t p_right = parity_lookup[p.data[k + 4] ^ p.data[k + 5] ^ 0x01]; 214 | 215 | p.data[k + 6] = (p_right << 7) | (p_left << 3) | 0x11; 216 | } 217 | 218 | data_encode(&p, hsync, vsync, true, tmds0, tmds1, tmds2); 219 | tmds0 += PACKET_BODY_LENGTH / 2; 220 | tmds1 += PACKET_BODY_LENGTH / 2; 221 | tmds2 += PACKET_BODY_LENGTH / 2; 222 | 223 | // trailing guard band (2 pixels) 224 | *(tmds0++) = terc4_sync; 225 | *(tmds1++) = DATA_ISLAND_GUARD_BAND; 226 | *(tmds2++) = DATA_ISLAND_GUARD_BAND; 227 | } -------------------------------------------------------------------------------- /src/ffifo.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #ifndef FFIFO_H 21 | #define FFIFO_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "pico/sync.h" 31 | #include "utils.h" 32 | 33 | #ifndef CUSTOM_FUNC 34 | #define CUSTOM_FUNC(a, ...) a##__VA_ARGS__ 35 | #endif 36 | 37 | #define FIFO_DEF(name, type) \ 38 | struct name { \ 39 | size_t read, write; \ 40 | size_t mask; \ 41 | type* data; \ 42 | }; \ 43 | \ 44 | static inline void CUSTOM_FUNC(name, _init)(struct name * f, \ 45 | size_t min_length) { \ 46 | assert(f); \ 47 | static_assert(sizeof(min_length) == sizeof(uint32_t)); \ 48 | uint32_t length = next_pow2(min_length); \ 49 | f->read = f->write = 0; \ 50 | f->mask = length - 1; \ 51 | f->data = malloc(sizeof(type) * length); \ 52 | } \ 53 | \ 54 | static inline void CUSTOM_FUNC(name, _destroy)(struct name * f) { \ 55 | assert(f && f->data); \ 56 | free(f->data); \ 57 | f->data = NULL; \ 58 | } \ 59 | \ 60 | static inline bool CUSTOM_FUNC(name, _empty)(struct name * f) { \ 61 | assert(f); \ 62 | return f->write == f->read; \ 63 | } \ 64 | \ 65 | static inline bool CUSTOM_FUNC(name, _full)(struct name * f) { \ 66 | assert(f); \ 67 | return ((f->write + 1) & f->mask) == f->read; \ 68 | } \ 69 | \ 70 | static inline bool CUSTOM_FUNC(name, _push)(struct name * f, \ 71 | type * data) { \ 72 | assert(f&& data); \ 73 | \ 74 | if(CUSTOM_FUNC(name, _full)(f)) \ 75 | return false; \ 76 | \ 77 | f->data[f->write] = *data; \ 78 | f->write = (f->write + 1) & f->mask; \ 79 | \ 80 | return true; \ 81 | } \ 82 | \ 83 | static inline bool CUSTOM_FUNC(name, _pop)(struct name * f, type * data) { \ 84 | assert(f&& data); \ 85 | \ 86 | if(CUSTOM_FUNC(name, _empty)(f)) \ 87 | return false; \ 88 | \ 89 | *data = f->data[f->read]; \ 90 | f->read = (f->read + 1) & f->mask; \ 91 | \ 92 | return true; \ 93 | } \ 94 | \ 95 | static inline bool CUSTOM_FUNC(name, _peek)(struct name * f, \ 96 | type * data) { \ 97 | assert(f&& data); \ 98 | \ 99 | if(CUSTOM_FUNC(name, _empty)(f)) \ 100 | return false; \ 101 | \ 102 | *data = f->data[f->read]; \ 103 | \ 104 | return true; \ 105 | } \ 106 | \ 107 | static inline void CUSTOM_FUNC(name, _push_blocking)(struct name * f, \ 108 | type * data) { \ 109 | assert(f&& data); \ 110 | \ 111 | while(1) { \ 112 | uint32_t mask = save_and_disable_interrupts(); \ 113 | \ 114 | if(CUSTOM_FUNC(name, _push)(f, data)) { \ 115 | restore_interrupts(mask); \ 116 | break; \ 117 | } \ 118 | \ 119 | restore_interrupts(mask); \ 120 | __wfi(); \ 121 | } \ 122 | } \ 123 | \ 124 | static inline void CUSTOM_FUNC(name, _pop_blocking)(struct name * f, \ 125 | type * data) { \ 126 | assert(f&& data); \ 127 | \ 128 | while(1) { \ 129 | uint32_t mask = save_and_disable_interrupts(); \ 130 | \ 131 | if(CUSTOM_FUNC(name, _pop)(f, data)) { \ 132 | restore_interrupts(mask); \ 133 | break; \ 134 | } \ 135 | \ 136 | restore_interrupts(mask); \ 137 | __wfi(); \ 138 | } \ 139 | } 140 | 141 | #endif -------------------------------------------------------------------------------- /src/gpu_input.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include "hardware/dma.h" 23 | #include "hardware/irq.h" 24 | #include "hardware/pio.h" 25 | #include "pico/platform.h" 26 | #include "pico/stdlib.h" 27 | #include "pico/util/queue.h" 28 | 29 | #include "capture.pio.h" 30 | #include "frame.h" 31 | #include "gpu_input.h" 32 | #include "i2s.pio.h" 33 | #include "utils.h" 34 | #include "video_output.h" 35 | 36 | #define DUMMY_BUFFER_LENGTH 256 37 | static uint32_t dummy_buffer; 38 | 39 | #define TS_HISTORY_LENGTH 4 40 | 41 | struct gpu_input { 42 | bool running; 43 | struct { 44 | bool data_skipped; 45 | uint dma_channels[2]; 46 | struct gpu_data* dma_data[2]; 47 | struct mem_pool pool; 48 | queue_t queue_receive; 49 | uint pio_sm; 50 | uint pio_program_offset[2]; 51 | } video; 52 | struct { 53 | uint dma_channels[2]; 54 | struct audio_data* dma_data[2]; 55 | struct mem_pool* pool_audio; 56 | queue_t* queue_receive; 57 | uint pio_sm; 58 | uint pio_program_offset; 59 | uint64_t timestamps[TS_HISTORY_LENGTH]; 60 | size_t timestamps_count; 61 | } audio; 62 | }; 63 | 64 | static struct gpu_input CORE1_DATA gi; 65 | 66 | static void CORE1_CODE dma_channel_set_write_incr(uint channel, bool incr) { 67 | dma_channel_config c = dma_get_channel_config(channel); 68 | channel_config_set_write_increment(&c, incr); 69 | dma_channel_set_config(channel, &c, false); 70 | } 71 | 72 | static void CORE1_CODE dma_isr1(void) { 73 | for(size_t k = 0; k < 2; k++) { 74 | // video 75 | if(dma_channel_get_irq1_status(gi.video.dma_channels[k])) { 76 | dma_channel_acknowledge_irq1(gi.video.dma_channels[k]); 77 | 78 | if(likely(gi.video.dma_data[k])) 79 | queue_try_add(&gi.video.queue_receive, gi.video.dma_data + k); 80 | 81 | gi.video.dma_data[k] 82 | = gi.running ? mem_pool_try_alloc(&gi.video.pool) : NULL; 83 | 84 | if(likely(gi.video.dma_data[k])) { 85 | gi.video.dma_data[k]->data_skipped = gi.video.data_skipped; 86 | gi.video.data_skipped = false; 87 | dma_channel_set_write_incr(gi.video.dma_channels[k], true); 88 | dma_channel_set_write_addr(gi.video.dma_channels[k], 89 | gi.video.dma_data[k]->ptr, false); 90 | dma_channel_set_trans_count(gi.video.dma_channels[k], 91 | gi.video.dma_data[k]->length, 92 | false); 93 | } else { 94 | gi.video.data_skipped = true; 95 | dma_channel_set_write_incr(gi.video.dma_channels[k], false); 96 | dma_channel_set_write_addr(gi.video.dma_channels[k], 97 | &dummy_buffer, false); 98 | dma_channel_set_trans_count(gi.video.dma_channels[k], 99 | DUMMY_BUFFER_LENGTH, false); 100 | } 101 | } 102 | 103 | // audio 104 | if(dma_channel_get_irq1_status(gi.audio.dma_channels[k])) { 105 | dma_channel_acknowledge_irq1(gi.audio.dma_channels[k]); 106 | 107 | uint64_t now = time_us_64(); 108 | uint32_t samplerate = 0; 109 | 110 | if(gi.audio.timestamps_count >= TS_HISTORY_LENGTH) { 111 | uint64_t time_diff = now - gi.audio.timestamps[0]; 112 | samplerate = (uint32_t)(AUDIO_FRAME_LENGTH * 1000 * 1000 113 | * TS_HISTORY_LENGTH 114 | + (uint32_t)time_diff / 2) 115 | / (uint32_t)time_diff; 116 | } else { 117 | gi.audio.timestamps_count++; 118 | } 119 | 120 | for(size_t i = 0; i < TS_HISTORY_LENGTH - 1; i++) 121 | gi.audio.timestamps[i] = gi.audio.timestamps[i + 1]; 122 | 123 | gi.audio.timestamps[TS_HISTORY_LENGTH - 1] = now; 124 | 125 | if(likely(gi.audio.dma_data[k])) { 126 | gi.audio.dma_data[k]->samplerate = samplerate; 127 | queue_try_add(gi.audio.queue_receive, gi.audio.dma_data + k); 128 | } 129 | 130 | gi.audio.dma_data[k] = mem_pool_try_alloc(gi.audio.pool_audio); 131 | 132 | if(likely(gi.audio.dma_data[k])) { 133 | dma_channel_set_write_incr(gi.audio.dma_channels[k], true); 134 | dma_channel_set_write_addr(gi.audio.dma_channels[k], 135 | gi.audio.dma_data[k]->audio_data, 136 | false); 137 | } else { 138 | dma_channel_set_write_incr(gi.audio.dma_channels[k], false); 139 | dma_channel_set_write_addr(gi.audio.dma_channels[k], 140 | &dummy_buffer, false); 141 | } 142 | 143 | dma_channel_set_trans_count(gi.audio.dma_channels[k], 144 | AUDIO_FRAME_LENGTH, false); 145 | } 146 | } 147 | } 148 | 149 | static void dma_gpu_configure(uint channel, uint other_channel, uint sm, 150 | void* ptr, size_t length) { 151 | assert(channel != other_channel); 152 | 153 | dma_channel_config c = dma_channel_get_default_config(channel); 154 | channel_config_set_transfer_data_size(&c, DMA_SIZE_32); 155 | channel_config_set_chain_to(&c, other_channel); 156 | channel_config_set_dreq(&c, pio_get_dreq(pio1, sm, false)); 157 | channel_config_set_read_increment(&c, false); 158 | channel_config_set_write_increment(&c, true); 159 | dma_channel_configure(channel, &c, ptr, &pio1->rxf[sm], length, false); 160 | dma_channel_set_irq1_enabled(channel, true); 161 | } 162 | 163 | static void* alloc_gpu_data(void* user) { 164 | size_t buffer_length = *(size_t*)user; 165 | struct gpu_data* obj = malloc(sizeof(struct gpu_data)); 166 | obj->length = buffer_length; 167 | obj->ptr = malloc(buffer_length * sizeof(uint32_t)); 168 | return obj; 169 | } 170 | 171 | void gpu_input_init(size_t capacity, size_t buffer_length, uint video_base, 172 | struct mem_pool* pool_audio, queue_t* receive_queue_audio, 173 | uint audio_base, uint audio_ws) { 174 | assert(capacity > 2 && buffer_length > 0); 175 | 176 | gi.running = false; 177 | 178 | // video 179 | 180 | gi.video.data_skipped = false; 181 | 182 | mem_pool_create(&gi.video.pool, alloc_gpu_data, capacity, &buffer_length); 183 | queue_init(&gi.video.queue_receive, sizeof(struct gpu_data*), capacity); 184 | 185 | gi.video.pio_sm = pio_claim_unused_sm(pio1, true); 186 | gi.video.pio_program_offset[0] 187 | = pio_add_program(pio1, &pio_capture_program); 188 | gi.video.pio_program_offset[1] 189 | = pio_add_program(pio1, &pio_capture_shifted_program); 190 | pio_capture_program_init(pio1, gi.video.pio_sm, 191 | gi.video.pio_program_offset[0], video_base); 192 | 193 | for(size_t k = 0; k < 2; k++) { 194 | gi.video.dma_channels[k] = dma_claim_unused_channel(true); 195 | gi.video.dma_data[k] = mem_pool_alloc(&gi.video.pool); 196 | } 197 | 198 | dma_gpu_configure(gi.video.dma_channels[0], gi.video.dma_channels[1], 199 | gi.video.pio_sm, gi.video.dma_data[0]->ptr, 200 | gi.video.dma_data[0]->length); 201 | dma_gpu_configure(gi.video.dma_channels[1], gi.video.dma_channels[0], 202 | gi.video.pio_sm, gi.video.dma_data[1]->ptr, 203 | gi.video.dma_data[1]->length); 204 | 205 | // audio 206 | 207 | gi.audio.timestamps_count = 0; 208 | gi.audio.pool_audio = pool_audio; 209 | gi.audio.queue_receive = receive_queue_audio; 210 | 211 | gi.audio.pio_sm = pio_claim_unused_sm(pio1, true); 212 | gi.audio.pio_program_offset = pio_add_program(pio1, &pio_i2s_program); 213 | pio_i2s_program_init(pio1, gi.audio.pio_sm, gi.audio.pio_program_offset, 214 | audio_base, audio_ws); 215 | 216 | for(size_t k = 0; k < 2; k++) { 217 | gi.audio.dma_channels[k] = dma_claim_unused_channel(true); 218 | gi.audio.dma_data[k] = mem_pool_alloc(gi.audio.pool_audio); 219 | } 220 | 221 | dma_gpu_configure(gi.audio.dma_channels[0], gi.audio.dma_channels[1], 222 | gi.audio.pio_sm, gi.audio.dma_data[0]->audio_data, 223 | AUDIO_FRAME_LENGTH); 224 | dma_gpu_configure(gi.audio.dma_channels[1], gi.audio.dma_channels[0], 225 | gi.audio.pio_sm, gi.audio.dma_data[1]->audio_data, 226 | AUDIO_FRAME_LENGTH); 227 | 228 | // general 229 | 230 | irq_set_exclusive_handler(DMA_IRQ_1, dma_isr1); 231 | irq_set_priority(DMA_IRQ_1, 0); 232 | irq_set_enabled(DMA_IRQ_1, true); 233 | } 234 | 235 | void gpu_input_start() { 236 | gi.running = true; 237 | 238 | // video 239 | 240 | pio_sm_set_enabled(pio1, gi.video.pio_sm, false); 241 | 242 | pio_sm_clear_fifos(pio1, gi.video.pio_sm); 243 | pio_sm_restart(pio1, gi.video.pio_sm); 244 | pio_sm_exec(pio1, gi.video.pio_sm, 245 | pio_encode_jmp(gi.video.pio_program_offset[0])); 246 | 247 | dma_channel_start(gi.video.dma_channels[0]); 248 | pio_sm_set_enabled(pio1, gi.video.pio_sm, true); 249 | 250 | // audio 251 | 252 | pio_sm_set_enabled(pio1, gi.audio.pio_sm, false); 253 | 254 | pio_sm_clear_fifos(pio1, gi.audio.pio_sm); 255 | pio_sm_restart(pio1, gi.audio.pio_sm); 256 | pio_sm_exec(pio1, gi.audio.pio_sm, 257 | pio_encode_jmp(gi.audio.pio_program_offset)); 258 | 259 | dma_channel_start(gi.audio.dma_channels[0]); 260 | pio_sm_set_enabled(pio1, gi.audio.pio_sm, true); 261 | } 262 | 263 | struct gpu_data* gpu_input_receive() { 264 | struct gpu_data* d; 265 | queue_remove_blocking(&gi.video.queue_receive, &d); 266 | return d; 267 | } 268 | 269 | void gpu_input_release(struct gpu_data* d) { 270 | mem_pool_free(&gi.video.pool, d); 271 | } 272 | 273 | void gpu_input_drain(bool shifted) { 274 | gi.running = false; 275 | 276 | while(mem_pool_any_allocated(&gi.video.pool)) 277 | gpu_input_release(gpu_input_receive()); 278 | 279 | pio_sm_set_enabled(pio1, gi.video.pio_sm, false); 280 | pio_sm_clear_fifos(pio1, gi.video.pio_sm); 281 | 282 | if(shifted) { 283 | pio_sm_set_wrap( 284 | pio1, gi.video.pio_sm, 285 | gi.video.pio_program_offset[1] + pio_capture_shifted_wrap_target, 286 | gi.video.pio_program_offset[1] + pio_capture_shifted_wrap); 287 | } else { 288 | pio_sm_set_wrap(pio1, gi.video.pio_sm, 289 | gi.video.pio_program_offset[0] 290 | + pio_capture_wrap_target, 291 | gi.video.pio_program_offset[0] + pio_capture_wrap); 292 | } 293 | 294 | gi.video.data_skipped = 0; 295 | gi.running = true; 296 | pio_sm_restart(pio1, gi.video.pio_sm); 297 | pio_sm_exec(pio1, gi.video.pio_sm, 298 | pio_encode_jmp(gi.video.pio_program_offset[shifted ? 1 : 0])); 299 | pio_sm_set_enabled(pio1, gi.video.pio_sm, true); 300 | } -------------------------------------------------------------------------------- /hardware/wii_mainboard/74AVC16T245DGGRE4.kicad_sym: -------------------------------------------------------------------------------- 1 | (kicad_symbol_lib (version 20220914) (generator kicad_symbol_editor) 2 | (symbol "74AVC16T245DGGRE4" (pin_names (offset 0.254)) (in_bom yes) (on_board yes) 3 | (property "Reference" "U" (at 20.32 10.16 0) 4 | (effects (font (size 1.524 1.524))) 5 | ) 6 | (property "Value" "74AVC16T245DGGRE4" (at 20.32 7.62 0) 7 | (effects (font (size 1.524 1.524))) 8 | ) 9 | (property "Footprint" "library:DGG48" (at 20.32 0 0) 10 | (effects (font (size 1.27 1.27) italic) hide) 11 | ) 12 | (property "Datasheet" "74AVC16T245DGGRE4" (at 20.32 2.54 0) 13 | (effects (font (size 1.27 1.27) italic) hide) 14 | ) 15 | (property "ki_keywords" "74AVC16T245DGGRE4" (at 0 0 0) 16 | (effects (font (size 1.27 1.27)) hide) 17 | ) 18 | (property "ki_fp_filters" "DGG48 DGG48-M DGG48-L" (at 0 0 0) 19 | (effects (font (size 1.27 1.27)) hide) 20 | ) 21 | (symbol "74AVC16T245DGGRE4_1_1" 22 | (rectangle (start 7.62 5.08) (end 33.02 -83.82) 23 | (stroke (width 0) (type default)) 24 | (fill (type background)) 25 | ) 26 | (pin input line (at 0 -5.08 0) (length 7.62) 27 | (name "1DIR" (effects (font (size 1.27 1.27)))) 28 | (number "1" (effects (font (size 1.27 1.27)))) 29 | ) 30 | (pin power_in line (at 40.64 -66.04 180) (length 7.62) 31 | (name "GND" (effects (font (size 1.27 1.27)))) 32 | (number "10" (effects (font (size 1.27 1.27)))) 33 | ) 34 | (pin bidirectional line (at 0 -27.94 0) (length 7.62) 35 | (name "1B7" (effects (font (size 1.27 1.27)))) 36 | (number "11" (effects (font (size 1.27 1.27)))) 37 | ) 38 | (pin bidirectional line (at 0 -30.48 0) (length 7.62) 39 | (name "1B8" (effects (font (size 1.27 1.27)))) 40 | (number "12" (effects (font (size 1.27 1.27)))) 41 | ) 42 | (pin bidirectional line (at 0 -35.56 0) (length 7.62) 43 | (name "2B1" (effects (font (size 1.27 1.27)))) 44 | (number "13" (effects (font (size 1.27 1.27)))) 45 | ) 46 | (pin bidirectional line (at 0 -38.1 0) (length 7.62) 47 | (name "2B2" (effects (font (size 1.27 1.27)))) 48 | (number "14" (effects (font (size 1.27 1.27)))) 49 | ) 50 | (pin power_in line (at 40.64 -68.58 180) (length 7.62) 51 | (name "GND" (effects (font (size 1.27 1.27)))) 52 | (number "15" (effects (font (size 1.27 1.27)))) 53 | ) 54 | (pin bidirectional line (at 0 -40.64 0) (length 7.62) 55 | (name "2B3" (effects (font (size 1.27 1.27)))) 56 | (number "16" (effects (font (size 1.27 1.27)))) 57 | ) 58 | (pin bidirectional line (at 0 -43.18 0) (length 7.62) 59 | (name "2B4" (effects (font (size 1.27 1.27)))) 60 | (number "17" (effects (font (size 1.27 1.27)))) 61 | ) 62 | (pin power_in line (at 40.64 -58.42 180) (length 7.62) 63 | (name "VCCB" (effects (font (size 1.27 1.27)))) 64 | (number "18" (effects (font (size 1.27 1.27)))) 65 | ) 66 | (pin bidirectional line (at 0 -45.72 0) (length 7.62) 67 | (name "2B5" (effects (font (size 1.27 1.27)))) 68 | (number "19" (effects (font (size 1.27 1.27)))) 69 | ) 70 | (pin bidirectional line (at 0 -12.7 0) (length 7.62) 71 | (name "1B1" (effects (font (size 1.27 1.27)))) 72 | (number "2" (effects (font (size 1.27 1.27)))) 73 | ) 74 | (pin bidirectional line (at 0 -48.26 0) (length 7.62) 75 | (name "2B6" (effects (font (size 1.27 1.27)))) 76 | (number "20" (effects (font (size 1.27 1.27)))) 77 | ) 78 | (pin power_in line (at 40.64 -71.12 180) (length 7.62) 79 | (name "GND" (effects (font (size 1.27 1.27)))) 80 | (number "21" (effects (font (size 1.27 1.27)))) 81 | ) 82 | (pin bidirectional line (at 0 -50.8 0) (length 7.62) 83 | (name "2B7" (effects (font (size 1.27 1.27)))) 84 | (number "22" (effects (font (size 1.27 1.27)))) 85 | ) 86 | (pin bidirectional line (at 0 -53.34 0) (length 7.62) 87 | (name "2B8" (effects (font (size 1.27 1.27)))) 88 | (number "23" (effects (font (size 1.27 1.27)))) 89 | ) 90 | (pin input line (at 0 -7.62 0) (length 7.62) 91 | (name "2DIR" (effects (font (size 1.27 1.27)))) 92 | (number "24" (effects (font (size 1.27 1.27)))) 93 | ) 94 | (pin input line (at 0 -2.54 0) (length 7.62) 95 | (name "*2OE" (effects (font (size 1.27 1.27)))) 96 | (number "25" (effects (font (size 1.27 1.27)))) 97 | ) 98 | (pin bidirectional line (at 40.64 -43.18 180) (length 7.62) 99 | (name "2A8" (effects (font (size 1.27 1.27)))) 100 | (number "26" (effects (font (size 1.27 1.27)))) 101 | ) 102 | (pin bidirectional line (at 40.64 -40.64 180) (length 7.62) 103 | (name "2A7" (effects (font (size 1.27 1.27)))) 104 | (number "27" (effects (font (size 1.27 1.27)))) 105 | ) 106 | (pin power_in line (at 40.64 -73.66 180) (length 7.62) 107 | (name "GND" (effects (font (size 1.27 1.27)))) 108 | (number "28" (effects (font (size 1.27 1.27)))) 109 | ) 110 | (pin bidirectional line (at 40.64 -38.1 180) (length 7.62) 111 | (name "2A6" (effects (font (size 1.27 1.27)))) 112 | (number "29" (effects (font (size 1.27 1.27)))) 113 | ) 114 | (pin bidirectional line (at 0 -15.24 0) (length 7.62) 115 | (name "1B2" (effects (font (size 1.27 1.27)))) 116 | (number "3" (effects (font (size 1.27 1.27)))) 117 | ) 118 | (pin bidirectional line (at 40.64 -35.56 180) (length 7.62) 119 | (name "2A5" (effects (font (size 1.27 1.27)))) 120 | (number "30" (effects (font (size 1.27 1.27)))) 121 | ) 122 | (pin power_in line (at 40.64 -48.26 180) (length 7.62) 123 | (name "VCCA" (effects (font (size 1.27 1.27)))) 124 | (number "31" (effects (font (size 1.27 1.27)))) 125 | ) 126 | (pin bidirectional line (at 40.64 -33.02 180) (length 7.62) 127 | (name "2A4" (effects (font (size 1.27 1.27)))) 128 | (number "32" (effects (font (size 1.27 1.27)))) 129 | ) 130 | (pin bidirectional line (at 40.64 -30.48 180) (length 7.62) 131 | (name "2A3" (effects (font (size 1.27 1.27)))) 132 | (number "33" (effects (font (size 1.27 1.27)))) 133 | ) 134 | (pin power_in line (at 40.64 -76.2 180) (length 7.62) 135 | (name "GND" (effects (font (size 1.27 1.27)))) 136 | (number "34" (effects (font (size 1.27 1.27)))) 137 | ) 138 | (pin bidirectional line (at 40.64 -27.94 180) (length 7.62) 139 | (name "2A2" (effects (font (size 1.27 1.27)))) 140 | (number "35" (effects (font (size 1.27 1.27)))) 141 | ) 142 | (pin bidirectional line (at 40.64 -25.4 180) (length 7.62) 143 | (name "2A1" (effects (font (size 1.27 1.27)))) 144 | (number "36" (effects (font (size 1.27 1.27)))) 145 | ) 146 | (pin bidirectional line (at 40.64 -20.32 180) (length 7.62) 147 | (name "1A8" (effects (font (size 1.27 1.27)))) 148 | (number "37" (effects (font (size 1.27 1.27)))) 149 | ) 150 | (pin bidirectional line (at 40.64 -17.78 180) (length 7.62) 151 | (name "1A7" (effects (font (size 1.27 1.27)))) 152 | (number "38" (effects (font (size 1.27 1.27)))) 153 | ) 154 | (pin power_in line (at 40.64 -78.74 180) (length 7.62) 155 | (name "GND" (effects (font (size 1.27 1.27)))) 156 | (number "39" (effects (font (size 1.27 1.27)))) 157 | ) 158 | (pin power_in line (at 40.64 -63.5 180) (length 7.62) 159 | (name "GND" (effects (font (size 1.27 1.27)))) 160 | (number "4" (effects (font (size 1.27 1.27)))) 161 | ) 162 | (pin bidirectional line (at 40.64 -15.24 180) (length 7.62) 163 | (name "1A6" (effects (font (size 1.27 1.27)))) 164 | (number "40" (effects (font (size 1.27 1.27)))) 165 | ) 166 | (pin bidirectional line (at 40.64 -12.7 180) (length 7.62) 167 | (name "1A5" (effects (font (size 1.27 1.27)))) 168 | (number "41" (effects (font (size 1.27 1.27)))) 169 | ) 170 | (pin power_in line (at 40.64 -50.8 180) (length 7.62) 171 | (name "VCCA" (effects (font (size 1.27 1.27)))) 172 | (number "42" (effects (font (size 1.27 1.27)))) 173 | ) 174 | (pin bidirectional line (at 40.64 -10.16 180) (length 7.62) 175 | (name "1A4" (effects (font (size 1.27 1.27)))) 176 | (number "43" (effects (font (size 1.27 1.27)))) 177 | ) 178 | (pin bidirectional line (at 40.64 -7.62 180) (length 7.62) 179 | (name "1A3" (effects (font (size 1.27 1.27)))) 180 | (number "44" (effects (font (size 1.27 1.27)))) 181 | ) 182 | (pin power_in line (at 40.64 -81.28 180) (length 7.62) 183 | (name "GND" (effects (font (size 1.27 1.27)))) 184 | (number "45" (effects (font (size 1.27 1.27)))) 185 | ) 186 | (pin bidirectional line (at 40.64 -5.08 180) (length 7.62) 187 | (name "1A2" (effects (font (size 1.27 1.27)))) 188 | (number "46" (effects (font (size 1.27 1.27)))) 189 | ) 190 | (pin bidirectional line (at 40.64 -2.54 180) (length 7.62) 191 | (name "1A1" (effects (font (size 1.27 1.27)))) 192 | (number "47" (effects (font (size 1.27 1.27)))) 193 | ) 194 | (pin input line (at 0 0 0) (length 7.62) 195 | (name "*1OE" (effects (font (size 1.27 1.27)))) 196 | (number "48" (effects (font (size 1.27 1.27)))) 197 | ) 198 | (pin bidirectional line (at 0 -17.78 0) (length 7.62) 199 | (name "1B3" (effects (font (size 1.27 1.27)))) 200 | (number "5" (effects (font (size 1.27 1.27)))) 201 | ) 202 | (pin bidirectional line (at 0 -20.32 0) (length 7.62) 203 | (name "1B4" (effects (font (size 1.27 1.27)))) 204 | (number "6" (effects (font (size 1.27 1.27)))) 205 | ) 206 | (pin power_in line (at 40.64 -55.88 180) (length 7.62) 207 | (name "VCCB" (effects (font (size 1.27 1.27)))) 208 | (number "7" (effects (font (size 1.27 1.27)))) 209 | ) 210 | (pin bidirectional line (at 0 -22.86 0) (length 7.62) 211 | (name "1B5" (effects (font (size 1.27 1.27)))) 212 | (number "8" (effects (font (size 1.27 1.27)))) 213 | ) 214 | (pin bidirectional line (at 0 -25.4 0) (length 7.62) 215 | (name "1B6" (effects (font (size 1.27 1.27)))) 216 | (number "9" (effects (font (size 1.27 1.27)))) 217 | ) 218 | ) 219 | ) 220 | ) 221 | -------------------------------------------------------------------------------- /src/video_output.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include "frame.h" 23 | #include "packet_info_frame.h" 24 | #include "pico/stdlib.h" 25 | #include "tmds_clock.h" 26 | #include "tmds_encode.h" 27 | #include "tmds_serializer.h" 28 | #include "utils.h" 29 | #include "video_output.h" 30 | 31 | FIFO_DEF(fifo_image, struct tmds_data3*) 32 | 33 | #define RATE_THRESHOLD (FRAME_HEIGHT * 60 * 4) 34 | 35 | struct video_output { 36 | struct tmds_clock channel_clock; 37 | struct tmds_serializer channels[TMDS_CHANNEL_COUNT]; 38 | struct fifo_image input_queue_video; 39 | struct fifo_image input_queue_packets; 40 | struct mem_pool* pool_video; 41 | struct mem_pool* pool_packets; 42 | struct { 43 | uint32_t rate_increase; 44 | uint32_t rate_current; 45 | bool active; 46 | size_t y; 47 | } state; 48 | struct tmds_data3 audio_info_packets[2]; 49 | size_t audio_info_idx; 50 | }; 51 | 52 | static uint32_t tmds_vsync_pulse0[FRAME_WIDTH / 2]; 53 | static uint32_t tmds_vsync_pulse1[FRAME_WIDTH / 2]; 54 | static uint32_t tmds_vsync_pulse2[FRAME_WIDTH / 2]; 55 | 56 | static uint32_t tmds_vsync_porch0[FRAME_WIDTH / 2]; 57 | static uint32_t tmds_vsync_porch1[FRAME_WIDTH / 2]; 58 | static uint32_t tmds_vsync_porch2[FRAME_WIDTH / 2]; 59 | 60 | static struct video_output CORE0_DATA vdo; 61 | static struct tmds_data3 CORE0_DATA video_signal_parts[] = { 62 | { 63 | .type = TYPE_CONST, 64 | .ptr = {tmds_vsync_porch0 + (FRAME_WIDTH - FRAME_BUFFER_WIDTH) / 2, 65 | tmds_vsync_porch1 + (FRAME_WIDTH - FRAME_BUFFER_WIDTH) / 2, 66 | tmds_vsync_porch2 + (FRAME_WIDTH - FRAME_BUFFER_WIDTH) / 2}, 67 | .length = FRAME_BUFFER_WIDTH / 2, 68 | }, 69 | { 70 | .type = TYPE_CONST, 71 | .ptr = {tmds_vsync_pulse0, tmds_vsync_pulse1, tmds_vsync_pulse2}, 72 | .length = FRAME_WIDTH / 2, 73 | }, 74 | { 75 | .type = TYPE_CONST, 76 | .ptr = {tmds_vsync_porch0, tmds_vsync_porch1, tmds_vsync_porch2}, 77 | .length = (FRAME_WIDTH - FRAME_BUFFER_WIDTH) / 2, 78 | }, 79 | { 80 | .type = TYPE_CONST, 81 | .ptr = {tmds_vsync_porch0, tmds_vsync_porch1, tmds_vsync_porch2}, 82 | .length = FRAME_WIDTH / 2, 83 | }, 84 | }; 85 | 86 | static void build_sync_tables(void) { 87 | tmds_encode_sync(FRAME_WIDTH, false, tmds_vsync_pulse0, tmds_vsync_pulse1, 88 | tmds_vsync_pulse2); 89 | tmds_encode_sync(FRAME_WIDTH, true, tmds_vsync_porch0, tmds_vsync_porch1, 90 | tmds_vsync_porch2); 91 | 92 | #ifndef DVI_ONLY 93 | struct packet packets[2]; 94 | packet_avi_info(packets + 0); 95 | packet_spd_info(packets + 1, "picoAVE", "picoAVE"); 96 | 97 | packets_encode(packets, sizeof(packets) / sizeof(*packets), true, false, 98 | tmds_vsync_pulse0 + FRAME_H_BLANK / 2, 99 | tmds_vsync_pulse1 + FRAME_H_BLANK / 2, 100 | tmds_vsync_pulse2 + FRAME_H_BLANK / 2); 101 | #endif 102 | } 103 | 104 | static struct tmds_data3* CORE0_CODE build_video_signal(void) { 105 | struct tmds_data3* result = NULL; 106 | 107 | if(!vdo.state.active) 108 | vdo.state.rate_current += vdo.state.rate_increase; 109 | 110 | if(vdo.state.y >= FRAME_V_PORCH_FRONT 111 | && vdo.state.y < FRAME_V_PORCH_FRONT + FRAME_V_SYNC) { 112 | result = video_signal_parts + 1; 113 | vdo.state.y++; 114 | } else if(vdo.state.y < FRAME_V_BLANK) { 115 | if(vdo.state.active) { 116 | result = video_signal_parts + 0; 117 | vdo.state.active = false; 118 | vdo.state.y++; 119 | } else { 120 | if(vdo.state.y == 0) { 121 | result = vdo.audio_info_packets + vdo.audio_info_idx; 122 | vdo.state.active = true; 123 | } else if(vdo.state.rate_current >= RATE_THRESHOLD 124 | && fifo_image_pop(&vdo.input_queue_packets, &result)) { 125 | vdo.state.rate_current -= RATE_THRESHOLD; 126 | vdo.state.active = true; 127 | } else { 128 | result = video_signal_parts + 3; 129 | vdo.state.y++; 130 | } 131 | } 132 | } else if(!vdo.state.active) { 133 | if(vdo.state.rate_current >= RATE_THRESHOLD 134 | && fifo_image_pop(&vdo.input_queue_packets, &result)) { 135 | vdo.state.rate_current -= RATE_THRESHOLD; 136 | } else { 137 | result = video_signal_parts + 2; 138 | } 139 | vdo.state.active = true; 140 | } else if(fifo_image_pop(&vdo.input_queue_video, &result)) { 141 | if(!(vdo.state.y == FRAME_V_BLANK && !result->vsync)) { 142 | vdo.state.y++; 143 | vdo.state.active = false; 144 | } 145 | } 146 | 147 | if(!result) { 148 | // last resort, provide anything to keep serializers in sync 149 | result = video_signal_parts + 0; 150 | vdo.state.y++; 151 | vdo.state.active = false; 152 | vdo.state.rate_current = 0; 153 | } 154 | 155 | if(vdo.state.y >= FRAME_HEIGHT) 156 | vdo.state.y = 0; 157 | 158 | return result; 159 | } 160 | 161 | static void CORE0_CODE refill_channels(void) { 162 | while(1) { 163 | for(size_t k = 0; k < TMDS_CHANNEL_COUNT; k++) { 164 | if(ffifo_full(&vdo.channels[k].queue_send)) 165 | return; 166 | } 167 | 168 | struct tmds_data3* data = build_video_signal(); 169 | 170 | if(data) { 171 | for(size_t k = 0; k < TMDS_CHANNEL_COUNT; k++) 172 | ffifo_push( 173 | &vdo.channels[k].queue_send, 174 | &(struct tmds_data) { 175 | .ptr = data->ptr[k], 176 | .length = data->length, 177 | .source = (data->type != TYPE_CONST) ? data : NULL, 178 | }); 179 | } 180 | } 181 | } 182 | 183 | static void CORE0_CODE dma_isr0(void) { 184 | struct tmds_data3* completed[TMDS_CHANNEL_COUNT]; 185 | 186 | // service serializers first, then release data later 187 | for(size_t k = 0; k < TMDS_CHANNEL_COUNT; k++) 188 | completed[k] = tmds_serializer_transfer_callback(vdo.channels + k); 189 | 190 | for(size_t k = 0; k < TMDS_CHANNEL_COUNT; k++) { 191 | if(completed[k] && (++completed[k]->transfers) >= TMDS_CHANNEL_COUNT) { 192 | switch(completed[k]->type) { 193 | case TYPE_VIDEO: 194 | mem_pool_free(vdo.pool_video, completed[k]); 195 | break; 196 | case TYPE_PACKET: 197 | mem_pool_free(vdo.pool_packets, completed[k]); 198 | break; 199 | default: 200 | } 201 | } 202 | } 203 | 204 | refill_channels(); 205 | } 206 | 207 | void video_output_init(uint gpio_channels[TMDS_CHANNEL_COUNT], uint gpio_clk, 208 | struct mem_pool* pool_video, 209 | struct mem_pool* pool_packets) { 210 | assert(pool_video && pool_packets); 211 | 212 | build_sync_tables(); 213 | 214 | fifo_image_init(&vdo.input_queue_video, mem_pool_capacity(pool_video)); 215 | fifo_image_init(&vdo.input_queue_packets, mem_pool_capacity(pool_packets)); 216 | vdo.pool_video = pool_video; 217 | vdo.pool_packets = pool_packets; 218 | 219 | vdo.state.rate_current = 0; 220 | vdo.state.y = 0; 221 | vdo.state.active = false; 222 | vdo.audio_info_idx = 0; 223 | 224 | for(size_t k = 0; k < 2; k++) { 225 | size_t len = (FRAME_WIDTH - FRAME_BUFFER_WIDTH) / 2; 226 | vdo.audio_info_packets[k] = (struct tmds_data3) { 227 | .type = TYPE_CONST, 228 | .length = len, 229 | .ptr 230 | = {malloc(len * sizeof(uint32_t)), malloc(len * sizeof(uint32_t)), 231 | malloc(len * sizeof(uint32_t))}, 232 | }; 233 | 234 | tmds_encode_sync(len * 2, true, vdo.audio_info_packets[k].ptr[0], 235 | vdo.audio_info_packets[k].ptr[1], 236 | vdo.audio_info_packets[k].ptr[2]); 237 | } 238 | 239 | video_output_set_audio_info(48000); 240 | 241 | tmds_serializer_init(); 242 | tmds_clock_init(); 243 | 244 | for(size_t k = 0; k < TMDS_CHANNEL_COUNT; k++) { 245 | tmds_serializer_create(vdo.channels + k, gpio_channels[k]); 246 | tmds_serializer_wait_ready(vdo.channels + k); 247 | } 248 | 249 | tmds_clock_create(&vdo.channel_clock, gpio_clk); 250 | 251 | irq_set_exclusive_handler(DMA_IRQ_0, dma_isr0); 252 | irq_set_priority(DMA_IRQ_0, 0); 253 | irq_set_enabled(DMA_IRQ_0, true); 254 | } 255 | 256 | void video_output_start() { 257 | tmds_start_with_clock(&vdo.channel_clock, vdo.channels, TMDS_CHANNEL_COUNT); 258 | } 259 | 260 | void video_output_submit(struct tmds_data3* data) { 261 | assert(data); 262 | 263 | if(data->type != TYPE_CONST) 264 | data->transfers = 0; 265 | 266 | switch(data->type) { 267 | case TYPE_CONST: 268 | case TYPE_VIDEO: 269 | fifo_image_push_blocking(&vdo.input_queue_video, &data); 270 | break; 271 | case TYPE_PACKET: 272 | fifo_image_push_blocking(&vdo.input_queue_packets, &data); 273 | break; 274 | } 275 | } 276 | 277 | // must be in this order to match audio info frame 278 | static int common_samplerates[][2] = { 279 | {32000, 4096}, {44100, 6272}, {48000, 6144}, {88200, 12544}, 280 | {96000, 12288}, {176400, 25088}, {192000, 24576}, 281 | }; 282 | 283 | static uint32_t audio_cts(uint32_t tmds_clk, uint32_t n, uint32_t samplerate) { 284 | return ((uint64_t)tmds_clk * 100 * (uint64_t)n / 128) 285 | / (uint64_t)samplerate; 286 | } 287 | 288 | void video_output_set_audio_info(uint32_t samplerate) { 289 | #ifndef DVI_ONLY 290 | // limit samplerate between -5% of 32kHz and +5% of 192kHz 291 | uint32_t sr_clamped 292 | = clamp_n(samplerate, 32000 * 95 / 100, 192000 * 105 / 100); 293 | 294 | size_t best_match = 0; 295 | int best_dist = INT_MAX; 296 | 297 | for(size_t k = 0; 298 | k < sizeof(common_samplerates) / sizeof(*common_samplerates); k++) { 299 | int dist = abs(common_samplerates[k][0] - (int)sr_clamped); 300 | 301 | if(dist < best_dist) { 302 | best_match = k; 303 | best_dist = dist; 304 | } 305 | } 306 | 307 | size_t other_packet = 1 - vdo.audio_info_idx; 308 | 309 | struct packet p; 310 | packet_audio_info(&p, best_match + 1); 311 | 312 | packets_encode( 313 | &p, 1, false, true, 314 | vdo.audio_info_packets[other_packet].ptr[0] + FRAME_H_PORCH_FRONT / 2, 315 | vdo.audio_info_packets[other_packet].ptr[1] + FRAME_H_PORCH_FRONT / 2, 316 | vdo.audio_info_packets[other_packet].ptr[2] + FRAME_H_PORCH_FRONT / 2); 317 | 318 | uint32_t audio_n = common_samplerates[best_match][1]; 319 | packet_audio_clk_regen(&p, audio_n, 320 | audio_cts(FRAME_CLOCK, audio_n, sr_clamped)); 321 | 322 | packets_encode(&p, 1, true, true, 323 | vdo.audio_info_packets[other_packet].ptr[0] 324 | + (FRAME_H_PORCH_FRONT + FRAME_H_SYNC) / 2, 325 | vdo.audio_info_packets[other_packet].ptr[1] 326 | + (FRAME_H_PORCH_FRONT + FRAME_H_SYNC) / 2, 327 | vdo.audio_info_packets[other_packet].ptr[2] 328 | + (FRAME_H_PORCH_FRONT + FRAME_H_SYNC) / 2); 329 | 330 | vdo.audio_info_idx = other_packet; 331 | vdo.state.rate_increase = sr_clamped; 332 | #endif 333 | } -------------------------------------------------------------------------------- /src/tmds_encode.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include "frame.h" 23 | #include "hardware/interp.h" 24 | #include "tmds_encode.h" 25 | #include "utils.h" 26 | 27 | static uint32_t tmds_symbol0[256 * 9]; 28 | static uint32_t tmds_symbol1[256 * 16]; 29 | 30 | // lsb is send first 31 | uint16_t tmds_terc4_symbols[16] = { 32 | 0x29c, 0x263, 0x2e4, 0x2e2, 0x171, 0x11e, 0x18e, 0x13c, 33 | 0x2cc, 0x139, 0x19c, 0x2c6, 0x28e, 0x271, 0x163, 0x2c3, 34 | }; 35 | 36 | // (vsync, hsync) 37 | uint32_t tmds_sync_symbols[4] = { 38 | 0xd5354, 39 | 0x2acab, 40 | 0x55154, 41 | 0xaaeab, 42 | }; 43 | 44 | uint32_t tmds_symbols_cbcr[9] = { 45 | /* 46 | bias -8, error 1.2047, (127,127) 47 | bias -6, error 2.2162, (122,129) 48 | bias -4, error 1.5960, (128,129) 49 | bias -2, error 0.0000, (128,128) 50 | bias 0, error 0.7835, (126,128) 51 | bias 2, error 0.8130, (128,127) 52 | bias 4, error 1.5965, (126,127) 53 | bias 6, error 2.2162, (122,129) 54 | bias 8, error 1.7652, (124,129) 55 | bias is 0 afterwards 56 | */ 57 | 0x1fc7f, 0x5fc7c, 0xe037f, 0x6037f, 0x6027f, 58 | 0x1fd80, 0x1fc80, 0xe0283, 0xe0281, 59 | }; 60 | 61 | uint32_t tmds_sync_lookup(bool vsync, bool hsync) { 62 | return tmds_sync_symbols[(vsync << 1) | hsync]; 63 | } 64 | 65 | static uint16_t symbol_encode(uint8_t b) { 66 | size_t ones = 0; 67 | 68 | for(size_t k = 0; k < 8; k++) 69 | ones += READ_BIT(b, k); 70 | 71 | uint16_t res = READ_BIT(b, 0); 72 | 73 | if(ones > 4 || (ones == 4 && !READ_BIT(b, 0))) { 74 | for(size_t k = 0; k <= 6; k++) 75 | res |= (!(READ_BIT(b, k + 1) ^ READ_BIT(res, k))) << (k + 1); 76 | } else { 77 | for(size_t k = 0; k <= 6; k++) 78 | res |= (READ_BIT(b, k + 1) ^ READ_BIT(res, k)) << (k + 1); 79 | 80 | res |= (1 << 8); 81 | } 82 | 83 | return res; 84 | } 85 | 86 | static int symbol_disparity(uint16_t b) { 87 | int ones = 0; 88 | 89 | for(size_t k = 0; k < 8; k++) 90 | ones += READ_BIT(b, k); 91 | 92 | return ones - (8 - ones); 93 | } 94 | 95 | static int symbol_dc_bias(int bias, uint16_t word, uint16_t* tmds_symbol) { 96 | int disparity = symbol_disparity(word); 97 | 98 | if(bias == 0 || disparity == 0) { 99 | if(READ_BIT(word, 8)) { 100 | *tmds_symbol = (1 << 8) | (word & 0xFF); 101 | return bias + disparity; 102 | } else { 103 | *tmds_symbol = (1 << 9) | (~word & 0xFF); 104 | return bias - disparity; 105 | } 106 | } else if((bias > 0 && disparity > 0) || (bias < 0 && disparity < 0)) { 107 | *tmds_symbol = (1 << 9) | (READ_BIT(word, 8) << 8) | (~word & 0xFF); 108 | return bias + 2 * READ_BIT(word, 8) - disparity; 109 | } else { 110 | *tmds_symbol = (0 << 9) | (READ_BIT(word, 8) << 8) | (word & 0xFF); 111 | return bias + disparity - 2 * READ_BIT(~word, 8); 112 | } 113 | } 114 | 115 | void tmds_encode_init() { 116 | for(int col = 0; col < 256; col++) { 117 | // {-8, -6, -4, -2, 0, 2, 4, 6, 8} 118 | for(int prev = 0; prev < 9; prev++) { 119 | uint16_t symbol; 120 | int next 121 | = (symbol_dc_bias(prev * 2 - 8, symbol_encode(col), &symbol) 122 | + 8) 123 | / 2; 124 | 125 | tmds_symbol0[(prev << 8) | col] = (next << 28) | (symbol << 10); 126 | tmds_symbol1[(col << 4) | prev] = (next << 28) | symbol; 127 | } 128 | } 129 | } 130 | 131 | void tmds_encode_setup() { 132 | interp_config c = interp_default_config(); 133 | interp_config_set_signed(&c, false); 134 | 135 | // 0x0000FF00 -> 0x000003FC 136 | interp_config_set_cross_input(&c, false); 137 | interp_config_set_shift(&c, 6); 138 | interp_config_set_mask(&c, 2, 9); 139 | interp_set_base(interp0, 0, (uint32_t)tmds_symbol0); 140 | interp_set_config(interp0, 0, &c); 141 | 142 | // 0xFF000000 -> 0x00003FC0 143 | interp_config_set_cross_input(&c, true); 144 | interp_config_set_shift(&c, 18); 145 | interp_config_set_mask(&c, 6, 13); 146 | interp_set_base(interp0, 1, (uint32_t)tmds_symbol1); 147 | interp_set_config(interp0, 1, &c); 148 | 149 | // interp1 has both pixels flipped 150 | // 0xFF000000 -> 0x000003FC 151 | interp_config_set_cross_input(&c, false); 152 | interp_config_set_shift(&c, 22); 153 | interp_config_set_mask(&c, 2, 9); 154 | interp_set_base(interp1, 0, (uint32_t)tmds_symbol0); 155 | interp_set_config(interp1, 0, &c); 156 | 157 | // 0x0000FF00 -> 0x00003FC0 158 | interp_config_set_cross_input(&c, true); 159 | interp_config_set_shift(&c, 2); 160 | interp_config_set_mask(&c, 6, 13); 161 | interp_set_base(interp1, 1, (uint32_t)tmds_symbol1); 162 | interp_set_config(interp1, 1, &c); 163 | } 164 | 165 | void tmds_encode_sync(size_t length, bool vsync, uint32_t* tmds0, 166 | uint32_t* tmds1, uint32_t* tmds2) { 167 | assert((length % 2) == 0); 168 | 169 | for(size_t k = 0; k < length / 2; k++) { 170 | bool hsync = k >= FRAME_H_PORCH_FRONT / 2 171 | && k < (FRAME_H_PORCH_FRONT + FRAME_H_SYNC) / 2; 172 | 173 | tmds0[k] = tmds_sync_lookup(vsync, !hsync); 174 | tmds1[k] = tmds_sync_symbols[0]; // CTL0 = 0, CTL1 = 0 175 | tmds2[k] = tmds_sync_symbols[0]; // CTL2 = 0, CTL3 = 0 176 | } 177 | } 178 | 179 | void tmds_encode_sync_video(uint32_t* tmds0, uint32_t* tmds1, uint32_t* tmds2) { 180 | static_assert((FRAME_H_BLANK % 2) == 0); 181 | 182 | /*for(size_t k = 0; k < FRAME_H_BLANK / 2; k++) { 183 | bool hsync = k >= FRAME_H_PORCH_FRONT / 2 184 | && k < (FRAME_H_PORCH_FRONT + FRAME_H_SYNC) / 2; 185 | 186 | if(k < (FRAME_H_BLANK - VIDEO_DATA_PREAMBLE_LENGTH - 2) / 2) { 187 | tmds0[k] = tmds_sync_lookup(true, !hsync); 188 | tmds1[k] = tmds_sync_symbols[0]; // CTL0 = 0, CTL1 = 0 189 | tmds2[k] = tmds_sync_symbols[0]; // CTL2 = 0, CTL3 = 0 190 | } else if(k == FRAME_H_BLANK / 2 - 1) { 191 | tmds0[k] = VIDEO_DATA_GUARD_BAND_0; 192 | tmds1[k] = VIDEO_DATA_GUARD_BAND_1; 193 | tmds2[k] = VIDEO_DATA_GUARD_BAND_2; 194 | } else { 195 | tmds0[k] = tmds_sync_lookup(true, !hsync); 196 | tmds1[k] = tmds_sync_symbols[1]; // CTL0 = 1, CTL1 = 0 197 | tmds2[k] = tmds_sync_symbols[0]; // CTL2 = 0, CTL3 = 0 198 | } 199 | }*/ 200 | 201 | #ifndef DVI_ONLY 202 | for(size_t k = 0; k < VIDEO_DATA_PREAMBLE_LENGTH / 2; k++) { 203 | tmds0[k] = tmds_sync_lookup(true, true); 204 | tmds1[k] = tmds_sync_symbols[1]; // CTL0 = 1, CTL1 = 0 205 | tmds2[k] = tmds_sync_symbols[0]; // CTL2 = 0, CTL3 = 0 206 | } 207 | 208 | tmds0[VIDEO_DATA_PREAMBLE_LENGTH / 2] = VIDEO_DATA_GUARD_BAND_0; 209 | tmds1[VIDEO_DATA_PREAMBLE_LENGTH / 2] = VIDEO_DATA_GUARD_BAND_1; 210 | tmds2[VIDEO_DATA_PREAMBLE_LENGTH / 2] = VIDEO_DATA_GUARD_BAND_2; 211 | #else 212 | for(size_t k = 0; k <= VIDEO_DATA_PREAMBLE_LENGTH / 2; k++) { 213 | tmds0[k] = tmds_sync_lookup(true, true); 214 | tmds1[k] = tmds_sync_symbols[0]; // CTL0 = 0, CTL1 = 0 215 | tmds2[k] = tmds_sync_symbols[0]; // CTL2 = 0, CTL3 = 0 216 | } 217 | #endif 218 | } 219 | 220 | uint32_t tmds_encode_y1y2(const uint32_t* pixbuf, size_t length, 221 | uint32_t* tmds) { 222 | uint32_t bias = 4 << 10; // (0 + 8) / 2 223 | 224 | asm volatile("loop%=:\n\t" 225 | "ldmia %[pixbuf]!,{%%r4,%%r5,%%r6}\n\t" 226 | 227 | "str %%r4,[%[interp],#0x00]\n\t" // accum 0 228 | 229 | "ldr %%r4,[%[interp],#0x20]\n\t" // lane0 peek 230 | "ldr %%r4,[%%r4,%[bias]]\n\t" 231 | "lsr %[bias],%%r4,#26\n\t" 232 | 233 | "ldr %%r7,[%[interp],#0x24]\n\t" // lane1 peek 234 | "ldr %%r7,[%%r7,%[bias]]\n\t" 235 | "lsr %[bias],%%r7,#18\n\t" 236 | "orr %%r4,%%r7\n\t" 237 | 238 | "str %%r5,[%[interp],#0x00]\n\t" 239 | 240 | "ldr %%r5,[%[interp],#0x20]\n\t" 241 | "ldr %%r5,[%%r5,%[bias]]\n\t" 242 | "lsr %[bias],%%r5,#26\n\t" 243 | 244 | "ldr %%r7,[%[interp],#0x24]\n\t" 245 | "ldr %%r7,[%%r7,%[bias]]\n\t" 246 | "lsr %[bias],%%r7,#18\n\t" 247 | "orr %%r5,%%r7\n\t" 248 | 249 | "str %%r6,[%[interp],#0x00]\n\t" 250 | 251 | "ldr %%r6,[%[interp],#0x20]\n\t" 252 | "ldr %%r6,[%%r6,%[bias]]\n\t" 253 | "lsr %[bias],%%r6,#26\n\t" 254 | 255 | "ldr %%r7,[%[interp],#0x24]\n\t" 256 | "ldr %%r7,[%%r7,%[bias]]\n\t" 257 | "lsr %[bias],%%r7,#18\n\t" 258 | "orr %%r6,%%r7\n\t" 259 | 260 | "stmia %[tmds]!,{%%r4,%%r5,%%r6}\n\t" 261 | "cmp %[end],%[pixbuf]\n\t" 262 | "bhi loop%=\n\t" 263 | : [bias] "+l"(bias), [pixbuf] "+l"(pixbuf), [tmds] "+l"(tmds) 264 | : [interp] "l"((uint32_t)interp0), [end] "h"(pixbuf + length) 265 | : "r4", "r5", "r6", "r7", "cc", "memory"); 266 | 267 | return bias >> 10; 268 | } 269 | 270 | // slower than y1y2 271 | uint32_t tmds_encode_cbcr(const uint32_t* pixbuf, size_t length, 272 | uint32_t* tmds) { 273 | uint32_t bias = 4 << 10; // (0 + 8) / 2 274 | 275 | asm volatile("loop%=:\n\t" 276 | "ldmia %[pixbuf]!,{%%r4,%%r5,%%r6}\n\t" 277 | 278 | "lsl %%r4, #8\n\t" 279 | "str %%r4,[%[interp],#0x00]\n\t" // accum 0 280 | 281 | "ldr %%r4,[%[interp],#0x20]\n\t" // lane0 peek 282 | "ldr %%r4,[%%r4,%[bias]]\n\t" 283 | "lsr %[bias],%%r4,#26\n\t" 284 | 285 | "ldr %%r7,[%[interp],#0x24]\n\t" // lane1 peek 286 | "ldr %%r7,[%%r7,%[bias]]\n\t" 287 | "lsr %[bias],%%r7,#18\n\t" 288 | "orr %%r4,%%r7\n\t" 289 | 290 | "lsl %%r5, #8\n\t" 291 | "str %%r5,[%[interp],#0x00]\n\t" 292 | 293 | "ldr %%r5,[%[interp],#0x20]\n\t" 294 | "ldr %%r5,[%%r5,%[bias]]\n\t" 295 | "lsr %[bias],%%r5,#26\n\t" 296 | 297 | "ldr %%r7,[%[interp],#0x24]\n\t" 298 | "ldr %%r7,[%%r7,%[bias]]\n\t" 299 | "lsr %[bias],%%r7,#18\n\t" 300 | "orr %%r5,%%r7\n\t" 301 | 302 | "lsl %%r6, #8\n\t" 303 | "str %%r6,[%[interp],#0x00]\n\t" 304 | 305 | "ldr %%r6,[%[interp],#0x20]\n\t" 306 | "ldr %%r6,[%%r6,%[bias]]\n\t" 307 | "lsr %[bias],%%r6,#26\n\t" 308 | 309 | "ldr %%r7,[%[interp],#0x24]\n\t" 310 | "ldr %%r7,[%%r7,%[bias]]\n\t" 311 | "lsr %[bias],%%r7,#18\n\t" 312 | "orr %%r6,%%r7\n\t" 313 | 314 | "stmia %[tmds]!,{%%r4,%%r5,%%r6}\n\t" 315 | "cmp %[end],%[pixbuf]\n\t" 316 | "bhi loop%=\n\t" 317 | : [bias] "+l"(bias), [pixbuf] "+l"(pixbuf), [tmds] "+l"(tmds) 318 | : [interp] "l"((uint32_t)interp1), [end] "h"(pixbuf + length) 319 | : "r4", "r5", "r6", "r7", "cc", "memory"); 320 | 321 | return bias >> 10; 322 | } 323 | -------------------------------------------------------------------------------- /src/font.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #include 21 | 22 | #include "font.h" 23 | #include "utils.h" 24 | 25 | #define FONT_SKIPPED 32 26 | #define FONT_STRIDE (128 - FONT_SKIPPED) 27 | 28 | // Spleen 8x16, https://github.com/fcambus/spleen 29 | // BSD 2-Clause license 30 | static uint8_t font[FONT_CHAR_HEIGHT * FONT_STRIDE] = { 31 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 34 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 35 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x66, 0x00, 0x08, 0x00, 0x00, 0x18, 0x70, 0x0e, 0x00, 0x00, 40 | 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 44 | 0x03, 0x3e, 0x08, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x18, 0x0e, 0x00, 0x00, 47 | 0x00, 0x18, 0x66, 0x36, 0x7e, 0x60, 0x1c, 0x18, 0x18, 0x18, 0x00, 0x00, 48 | 0x00, 0x00, 0x00, 0x60, 0x3e, 0x18, 0x3e, 0x3e, 0x03, 0x7f, 0x3e, 0x7f, 49 | 0x3e, 0x3e, 0x00, 0x00, 0x60, 0x00, 0x06, 0x3e, 0x00, 0x3e, 0x3f, 0x7e, 50 | 0x3f, 0x7e, 0x7e, 0x7e, 0x63, 0x7e, 0x7e, 0x63, 0x03, 0x63, 0x63, 0x3e, 51 | 0x3f, 0x3e, 0x3f, 0x7e, 0xff, 0x63, 0x63, 0x63, 0x63, 0x63, 0x7f, 0x0c, 52 | 0x03, 0x30, 0x1c, 0x00, 0x18, 0x00, 0x03, 0x00, 0x60, 0x00, 0x78, 0x00, 53 | 0x03, 0x18, 0x18, 0x03, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 54 | 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 55 | 0x00, 0x18, 0x66, 0x36, 0x0b, 0x66, 0x36, 0x18, 0x0c, 0x30, 0x00, 0x00, 56 | 0x00, 0x00, 0x00, 0x30, 0x63, 0x1c, 0x63, 0x63, 0x03, 0x63, 0x63, 0x63, 57 | 0x63, 0x63, 0x00, 0x00, 0x30, 0x00, 0x0c, 0x63, 0x3e, 0x63, 0x63, 0x03, 58 | 0x63, 0x03, 0x03, 0x03, 0x63, 0x18, 0x18, 0x63, 0x03, 0x77, 0x63, 0x63, 59 | 0x63, 0x63, 0x63, 0x03, 0x18, 0x63, 0x63, 0x63, 0x63, 0x63, 0x60, 0x0c, 60 | 0x06, 0x30, 0x36, 0x00, 0x30, 0x00, 0x03, 0x00, 0x60, 0x00, 0x0c, 0x00, 61 | 0x03, 0x18, 0x18, 0x03, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62 | 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 63 | 0x00, 0x18, 0x66, 0x7f, 0x0b, 0x36, 0x36, 0x18, 0x0c, 0x30, 0x66, 0x00, 64 | 0x00, 0x00, 0x00, 0x30, 0x63, 0x1e, 0x60, 0x60, 0x33, 0x03, 0x03, 0x60, 65 | 0x63, 0x63, 0x00, 0x00, 0x18, 0x00, 0x18, 0x60, 0x43, 0x63, 0x63, 0x03, 66 | 0x63, 0x03, 0x03, 0x03, 0x63, 0x18, 0x18, 0x63, 0x03, 0x7f, 0x67, 0x63, 67 | 0x63, 0x63, 0x63, 0x03, 0x18, 0x63, 0x63, 0x63, 0x63, 0x63, 0x60, 0x0c, 68 | 0x06, 0x30, 0x63, 0x00, 0x00, 0x00, 0x03, 0x00, 0x60, 0x00, 0x0c, 0x00, 69 | 0x03, 0x00, 0x00, 0x03, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 70 | 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 71 | 0x00, 0x18, 0x00, 0x36, 0x0b, 0x30, 0x36, 0x00, 0x06, 0x60, 0x3c, 0x18, 72 | 0x00, 0x00, 0x00, 0x18, 0x73, 0x1a, 0x60, 0x60, 0x33, 0x03, 0x03, 0x60, 73 | 0x63, 0x63, 0x18, 0x18, 0x0c, 0x7e, 0x30, 0x30, 0x5b, 0x63, 0x63, 0x03, 74 | 0x63, 0x03, 0x03, 0x03, 0x63, 0x18, 0x18, 0x33, 0x03, 0x6b, 0x67, 0x63, 75 | 0x63, 0x63, 0x63, 0x03, 0x18, 0x63, 0x63, 0x63, 0x36, 0x63, 0x30, 0x0c, 76 | 0x0c, 0x30, 0x00, 0x00, 0x00, 0x3e, 0x3f, 0x7e, 0x7e, 0x7e, 0x0c, 0x7e, 77 | 0x3f, 0x1c, 0x18, 0x33, 0x0c, 0x37, 0x3f, 0x3e, 0x3f, 0x7e, 0x7e, 0x7e, 78 | 0x3e, 0x63, 0x63, 0x63, 0x63, 0x63, 0x7f, 0x18, 0x18, 0x18, 0x00, 0x00, 79 | 0x00, 0x18, 0x00, 0x36, 0x3e, 0x18, 0x1c, 0x00, 0x06, 0x60, 0x18, 0x18, 80 | 0x00, 0x00, 0x00, 0x18, 0x7b, 0x18, 0x30, 0x3c, 0x33, 0x3f, 0x3f, 0x30, 81 | 0x3e, 0x63, 0x18, 0x18, 0x06, 0x00, 0x60, 0x18, 0x5b, 0x7f, 0x3f, 0x03, 82 | 0x63, 0x1f, 0x1f, 0x7b, 0x7f, 0x18, 0x18, 0x1f, 0x03, 0x63, 0x6b, 0x63, 83 | 0x3f, 0x63, 0x3f, 0x3e, 0x18, 0x63, 0x63, 0x63, 0x1c, 0x7e, 0x18, 0x0c, 84 | 0x0c, 0x30, 0x00, 0x00, 0x00, 0x60, 0x63, 0x03, 0x63, 0x63, 0x3e, 0x63, 85 | 0x63, 0x18, 0x18, 0x1b, 0x0c, 0x6b, 0x63, 0x63, 0x63, 0x63, 0x63, 0x03, 86 | 0x0c, 0x63, 0x63, 0x63, 0x36, 0x63, 0x60, 0x0e, 0x18, 0x70, 0x4c, 0x00, 87 | 0x00, 0x18, 0x00, 0x36, 0x68, 0x18, 0x0e, 0x00, 0x06, 0x60, 0xff, 0x7e, 88 | 0x00, 0x7e, 0x00, 0x0c, 0x6f, 0x18, 0x18, 0x60, 0x33, 0x60, 0x63, 0x18, 89 | 0x63, 0x7e, 0x00, 0x00, 0x06, 0x00, 0x60, 0x0c, 0x5b, 0x63, 0x63, 0x03, 90 | 0x63, 0x03, 0x03, 0x63, 0x63, 0x18, 0x18, 0x33, 0x03, 0x63, 0x6b, 0x63, 91 | 0x03, 0x63, 0x63, 0x60, 0x18, 0x63, 0x63, 0x63, 0x36, 0x60, 0x0c, 0x0c, 92 | 0x18, 0x30, 0x00, 0x00, 0x00, 0x7e, 0x63, 0x03, 0x63, 0x63, 0x0c, 0x63, 93 | 0x63, 0x18, 0x18, 0x0f, 0x0c, 0x6b, 0x63, 0x63, 0x63, 0x63, 0x03, 0x03, 94 | 0x0c, 0x63, 0x63, 0x6b, 0x1c, 0x63, 0x30, 0x0e, 0x18, 0x70, 0x7e, 0x00, 95 | 0x00, 0x18, 0x00, 0x36, 0x68, 0x0c, 0x5b, 0x00, 0x06, 0x60, 0x18, 0x18, 96 | 0x00, 0x00, 0x00, 0x0c, 0x67, 0x18, 0x0c, 0x60, 0x7f, 0x60, 0x63, 0x0c, 97 | 0x63, 0x60, 0x00, 0x00, 0x0c, 0x7e, 0x30, 0x0c, 0x5b, 0x63, 0x63, 0x03, 98 | 0x63, 0x03, 0x03, 0x63, 0x63, 0x18, 0x18, 0x63, 0x03, 0x63, 0x73, 0x63, 99 | 0x03, 0x63, 0x63, 0x60, 0x18, 0x63, 0x63, 0x6b, 0x63, 0x60, 0x06, 0x0c, 100 | 0x18, 0x30, 0x00, 0x00, 0x00, 0x63, 0x63, 0x03, 0x63, 0x7f, 0x0c, 0x63, 101 | 0x63, 0x18, 0x18, 0x0f, 0x0c, 0x6b, 0x63, 0x63, 0x63, 0x63, 0x03, 0x3e, 102 | 0x0c, 0x63, 0x63, 0x6b, 0x1c, 0x63, 0x18, 0x18, 0x18, 0x18, 0x32, 0x00, 103 | 0x00, 0x00, 0x00, 0x7f, 0x68, 0x6c, 0x33, 0x00, 0x0c, 0x30, 0x3c, 0x18, 104 | 0x00, 0x00, 0x00, 0x06, 0x63, 0x18, 0x06, 0x60, 0x30, 0x60, 0x63, 0x0c, 105 | 0x63, 0x60, 0x00, 0x00, 0x18, 0x00, 0x18, 0x00, 0x7b, 0x63, 0x63, 0x03, 106 | 0x63, 0x03, 0x03, 0x63, 0x63, 0x18, 0x18, 0x63, 0x03, 0x63, 0x73, 0x63, 107 | 0x03, 0x6b, 0x63, 0x60, 0x18, 0x63, 0x36, 0x7f, 0x63, 0x60, 0x03, 0x0c, 108 | 0x30, 0x30, 0x00, 0x00, 0x00, 0x63, 0x63, 0x03, 0x63, 0x03, 0x0c, 0x63, 109 | 0x63, 0x18, 0x18, 0x1b, 0x0c, 0x6b, 0x63, 0x63, 0x63, 0x63, 0x03, 0x60, 110 | 0x0c, 0x63, 0x36, 0x6b, 0x36, 0x63, 0x0c, 0x18, 0x18, 0x18, 0x00, 0x00, 111 | 0x00, 0x18, 0x00, 0x36, 0x68, 0x66, 0x33, 0x00, 0x0c, 0x30, 0x66, 0x00, 112 | 0x18, 0x00, 0x18, 0x06, 0x63, 0x18, 0x63, 0x63, 0x30, 0x63, 0x63, 0x0c, 113 | 0x63, 0x63, 0x18, 0x18, 0x30, 0x00, 0x0c, 0x0c, 0x03, 0x63, 0x63, 0x03, 114 | 0x63, 0x03, 0x03, 0x63, 0x63, 0x18, 0x18, 0x63, 0x03, 0x63, 0x63, 0x63, 115 | 0x03, 0x6b, 0x63, 0x60, 0x18, 0x63, 0x1c, 0x77, 0x63, 0x60, 0x03, 0x0c, 116 | 0x30, 0x30, 0x00, 0x00, 0x00, 0x63, 0x63, 0x03, 0x63, 0x03, 0x0c, 0x63, 117 | 0x63, 0x18, 0x18, 0x33, 0x0c, 0x63, 0x63, 0x63, 0x63, 0x63, 0x03, 0x60, 118 | 0x0c, 0x63, 0x1c, 0x6b, 0x63, 0x63, 0x06, 0x18, 0x18, 0x18, 0x00, 0x00, 119 | 0x00, 0x18, 0x00, 0x36, 0x3f, 0x06, 0x5e, 0x00, 0x18, 0x18, 0x00, 0x00, 120 | 0x18, 0x00, 0x18, 0x03, 0x3e, 0x7e, 0x7f, 0x3e, 0x30, 0x3e, 0x3e, 0x0c, 121 | 0x3e, 0x3e, 0x18, 0x18, 0x60, 0x00, 0x06, 0x0c, 0x3e, 0x63, 0x3f, 0x7e, 122 | 0x3f, 0x7e, 0x03, 0x7e, 0x63, 0x7e, 0x0f, 0x63, 0x7e, 0x63, 0x63, 0x3e, 123 | 0x03, 0x3e, 0x63, 0x3f, 0x18, 0x7e, 0x08, 0x63, 0x63, 0x3f, 0x7f, 0x0c, 124 | 0x60, 0x30, 0x00, 0x00, 0x00, 0x7e, 0x3f, 0x7e, 0x7e, 0x7e, 0x0c, 0x3e, 125 | 0x63, 0x38, 0x18, 0x63, 0x38, 0x63, 0x63, 0x3e, 0x3f, 0x7e, 0x03, 0x3f, 126 | 0x78, 0x7e, 0x08, 0x76, 0x63, 0x7e, 0x7f, 0x18, 0x18, 0x18, 0x00, 0x00, 127 | 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x70, 0x0e, 0x00, 0x00, 128 | 0x0c, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 129 | 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 130 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 131 | 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 132 | 0x60, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 133 | 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x60, 0x00, 0x00, 134 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x70, 0x18, 0x0e, 0x00, 0x00, 135 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 136 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 137 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 138 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 139 | 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 140 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 141 | 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x60, 0x00, 0x00, 142 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 143 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 144 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 145 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 146 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 147 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 148 | 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 149 | 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x60, 0x00, 0x00, 150 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 151 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 152 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 153 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 154 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 155 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 156 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 157 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 158 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 159 | }; 160 | 161 | static uint32_t pixel_color2[4] = { 162 | 0x10801080, 163 | 0xeb801080, 164 | 0x1080eb80, 165 | 0xeb80eb80, 166 | }; 167 | 168 | size_t font_encode(const char* str, size_t y, uint32_t* pixbuf) { 169 | uint32_t* pixel = pixbuf; 170 | uint8_t* tmp = font + y * FONT_STRIDE - FONT_SKIPPED; 171 | 172 | while(*str) { 173 | uint32_t f = tmp[(size_t)(*(str++))] << 2; 174 | 175 | for(size_t i = 0; i < FONT_CHAR_WIDTH / 2; i++) { 176 | *(pixel++) = *(uint32_t*)((uintptr_t)pixel_color2 + (f & 12)); 177 | f >>= 2; 178 | } 179 | } 180 | 181 | return pixel - pixbuf; 182 | } 183 | 184 | size_t font_width(const char* str) { 185 | return strlen(str) * FONT_CHAR_WIDTH / 2; 186 | } -------------------------------------------------------------------------------- /hardware/wii_mainboard/wii_mainboard.kicad_pro: -------------------------------------------------------------------------------- 1 | { 2 | "board": { 3 | "3dviewports": [], 4 | "design_settings": { 5 | "defaults": { 6 | "board_outline_line_width": 0.09999999999999999, 7 | "copper_line_width": 0.19999999999999998, 8 | "copper_text_italic": false, 9 | "copper_text_size_h": 1.5, 10 | "copper_text_size_v": 1.5, 11 | "copper_text_thickness": 0.3, 12 | "copper_text_upright": false, 13 | "courtyard_line_width": 0.049999999999999996, 14 | "dimension_precision": 4, 15 | "dimension_units": 3, 16 | "dimensions": { 17 | "arrow_length": 1270000, 18 | "extension_offset": 500000, 19 | "keep_text_aligned": true, 20 | "suppress_zeroes": false, 21 | "text_position": 0, 22 | "units_format": 1 23 | }, 24 | "fab_line_width": 0.09999999999999999, 25 | "fab_text_italic": false, 26 | "fab_text_size_h": 1.0, 27 | "fab_text_size_v": 1.0, 28 | "fab_text_thickness": 0.15, 29 | "fab_text_upright": false, 30 | "other_line_width": 0.15, 31 | "other_text_italic": false, 32 | "other_text_size_h": 1.0, 33 | "other_text_size_v": 1.0, 34 | "other_text_thickness": 0.15, 35 | "other_text_upright": false, 36 | "pads": { 37 | "drill": 0.0, 38 | "height": 1.7, 39 | "width": 1.7 40 | }, 41 | "silk_line_width": 0.15, 42 | "silk_text_italic": false, 43 | "silk_text_size_h": 1.0, 44 | "silk_text_size_v": 1.0, 45 | "silk_text_thickness": 0.15, 46 | "silk_text_upright": false, 47 | "zones": { 48 | "min_clearance": 0.15239999999999998 49 | } 50 | }, 51 | "diff_pair_dimensions": [ 52 | { 53 | "gap": 0.0, 54 | "via_gap": 0.0, 55 | "width": 0.0 56 | } 57 | ], 58 | "drc_exclusions": [], 59 | "meta": { 60 | "version": 2 61 | }, 62 | "rule_severities": { 63 | "annular_width": "error", 64 | "clearance": "error", 65 | "connection_width": "warning", 66 | "copper_edge_clearance": "error", 67 | "copper_sliver": "warning", 68 | "courtyards_overlap": "error", 69 | "diff_pair_gap_out_of_range": "error", 70 | "diff_pair_uncoupled_length_too_long": "error", 71 | "drill_out_of_range": "error", 72 | "duplicate_footprints": "warning", 73 | "extra_footprint": "warning", 74 | "footprint": "error", 75 | "footprint_type_mismatch": "error", 76 | "hole_clearance": "error", 77 | "hole_near_hole": "error", 78 | "invalid_outline": "error", 79 | "isolated_copper": "warning", 80 | "item_on_disabled_layer": "error", 81 | "items_not_allowed": "error", 82 | "length_out_of_range": "error", 83 | "lib_footprint_issues": "warning", 84 | "lib_footprint_mismatch": "warning", 85 | "malformed_courtyard": "error", 86 | "microvia_drill_out_of_range": "error", 87 | "missing_courtyard": "ignore", 88 | "missing_footprint": "warning", 89 | "net_conflict": "warning", 90 | "npth_inside_courtyard": "warning", 91 | "padstack": "warning", 92 | "pth_inside_courtyard": "warning", 93 | "shorting_items": "error", 94 | "silk_edge_clearance": "warning", 95 | "silk_over_copper": "warning", 96 | "silk_overlap": "ignore", 97 | "skew_out_of_range": "error", 98 | "solder_mask_bridge": "error", 99 | "starved_thermal": "error", 100 | "text_height": "ignore", 101 | "text_thickness": "warning", 102 | "through_hole_pad_without_hole": "error", 103 | "too_many_vias": "error", 104 | "track_dangling": "warning", 105 | "track_width": "error", 106 | "tracks_crossing": "error", 107 | "unconnected_items": "error", 108 | "unresolved_variable": "error", 109 | "via_dangling": "warning", 110 | "zones_intersect": "error" 111 | }, 112 | "rules": { 113 | "max_error": 0.005, 114 | "min_clearance": 0.0, 115 | "min_connection": 0.0, 116 | "min_copper_edge_clearance": 0.3, 117 | "min_hole_clearance": 0.25, 118 | "min_hole_to_hole": 0.25, 119 | "min_microvia_diameter": 0.19999999999999998, 120 | "min_microvia_drill": 0.09999999999999999, 121 | "min_resolved_spokes": 2, 122 | "min_silk_clearance": 0.15, 123 | "min_text_height": 1.0, 124 | "min_text_thickness": 0.08, 125 | "min_through_hole_diameter": 0.3, 126 | "min_track_width": 0.0, 127 | "min_via_annular_width": 0.09999999999999999, 128 | "min_via_diameter": 0.5, 129 | "solder_mask_clearance": 0.0, 130 | "solder_mask_min_width": 0.0, 131 | "solder_mask_to_copper_clearance": 0.005, 132 | "use_height_for_length_calcs": true 133 | }, 134 | "teardrop_options": [ 135 | { 136 | "td_allow_use_two_tracks": true, 137 | "td_curve_segcount": 5, 138 | "td_on_pad_in_zone": false, 139 | "td_onpadsmd": true, 140 | "td_onroundshapesonly": false, 141 | "td_ontrackend": false, 142 | "td_onviapad": true 143 | } 144 | ], 145 | "teardrop_parameters": [ 146 | { 147 | "td_curve_segcount": 0, 148 | "td_height_ratio": 1.0, 149 | "td_length_ratio": 0.5, 150 | "td_maxheight": 2.0, 151 | "td_maxlen": 1.0, 152 | "td_target_name": "td_round_shape", 153 | "td_width_to_size_filter_ratio": 0.9 154 | }, 155 | { 156 | "td_curve_segcount": 0, 157 | "td_height_ratio": 1.0, 158 | "td_length_ratio": 0.5, 159 | "td_maxheight": 2.0, 160 | "td_maxlen": 1.0, 161 | "td_target_name": "td_rect_shape", 162 | "td_width_to_size_filter_ratio": 0.9 163 | }, 164 | { 165 | "td_curve_segcount": 0, 166 | "td_height_ratio": 1.0, 167 | "td_length_ratio": 0.5, 168 | "td_maxheight": 2.0, 169 | "td_maxlen": 1.0, 170 | "td_target_name": "td_track_end", 171 | "td_width_to_size_filter_ratio": 0.9 172 | } 173 | ], 174 | "track_widths": [ 175 | 0.0 176 | ], 177 | "via_dimensions": [ 178 | { 179 | "diameter": 0.0, 180 | "drill": 0.0 181 | } 182 | ], 183 | "zones_allow_external_fillets": false 184 | }, 185 | "layer_presets": [], 186 | "viewports": [] 187 | }, 188 | "boards": [], 189 | "cvpcb": { 190 | "equivalence_files": [] 191 | }, 192 | "erc": { 193 | "erc_exclusions": [], 194 | "meta": { 195 | "version": 0 196 | }, 197 | "pin_map": [ 198 | [ 199 | 0, 200 | 0, 201 | 0, 202 | 0, 203 | 0, 204 | 0, 205 | 1, 206 | 0, 207 | 0, 208 | 0, 209 | 0, 210 | 2 211 | ], 212 | [ 213 | 0, 214 | 2, 215 | 0, 216 | 1, 217 | 0, 218 | 0, 219 | 1, 220 | 0, 221 | 2, 222 | 2, 223 | 2, 224 | 2 225 | ], 226 | [ 227 | 0, 228 | 0, 229 | 0, 230 | 0, 231 | 0, 232 | 0, 233 | 1, 234 | 0, 235 | 1, 236 | 0, 237 | 1, 238 | 2 239 | ], 240 | [ 241 | 0, 242 | 1, 243 | 0, 244 | 0, 245 | 0, 246 | 0, 247 | 1, 248 | 1, 249 | 2, 250 | 1, 251 | 1, 252 | 2 253 | ], 254 | [ 255 | 0, 256 | 0, 257 | 0, 258 | 0, 259 | 0, 260 | 0, 261 | 1, 262 | 0, 263 | 0, 264 | 0, 265 | 0, 266 | 2 267 | ], 268 | [ 269 | 0, 270 | 0, 271 | 0, 272 | 0, 273 | 0, 274 | 0, 275 | 0, 276 | 0, 277 | 0, 278 | 0, 279 | 0, 280 | 2 281 | ], 282 | [ 283 | 1, 284 | 1, 285 | 1, 286 | 1, 287 | 1, 288 | 0, 289 | 1, 290 | 1, 291 | 1, 292 | 1, 293 | 1, 294 | 2 295 | ], 296 | [ 297 | 0, 298 | 0, 299 | 0, 300 | 1, 301 | 0, 302 | 0, 303 | 1, 304 | 0, 305 | 0, 306 | 0, 307 | 0, 308 | 2 309 | ], 310 | [ 311 | 0, 312 | 2, 313 | 1, 314 | 2, 315 | 0, 316 | 0, 317 | 1, 318 | 0, 319 | 2, 320 | 2, 321 | 2, 322 | 2 323 | ], 324 | [ 325 | 0, 326 | 2, 327 | 0, 328 | 1, 329 | 0, 330 | 0, 331 | 1, 332 | 0, 333 | 2, 334 | 0, 335 | 0, 336 | 2 337 | ], 338 | [ 339 | 0, 340 | 2, 341 | 1, 342 | 1, 343 | 0, 344 | 0, 345 | 1, 346 | 0, 347 | 2, 348 | 0, 349 | 0, 350 | 2 351 | ], 352 | [ 353 | 2, 354 | 2, 355 | 2, 356 | 2, 357 | 2, 358 | 2, 359 | 2, 360 | 2, 361 | 2, 362 | 2, 363 | 2, 364 | 2 365 | ] 366 | ], 367 | "rule_severities": { 368 | "bus_definition_conflict": "error", 369 | "bus_entry_needed": "error", 370 | "bus_to_bus_conflict": "error", 371 | "bus_to_net_conflict": "error", 372 | "conflicting_netclasses": "error", 373 | "different_unit_footprint": "error", 374 | "different_unit_net": "error", 375 | "duplicate_reference": "error", 376 | "duplicate_sheet_names": "error", 377 | "endpoint_off_grid": "warning", 378 | "extra_units": "error", 379 | "global_label_dangling": "warning", 380 | "hier_label_mismatch": "error", 381 | "label_dangling": "error", 382 | "lib_symbol_issues": "warning", 383 | "missing_bidi_pin": "warning", 384 | "missing_input_pin": "warning", 385 | "missing_power_pin": "error", 386 | "missing_unit": "warning", 387 | "multiple_net_names": "warning", 388 | "net_not_bus_member": "warning", 389 | "no_connect_connected": "warning", 390 | "no_connect_dangling": "warning", 391 | "pin_not_connected": "error", 392 | "pin_not_driven": "error", 393 | "pin_to_pin": "error", 394 | "power_pin_not_driven": "error", 395 | "similar_labels": "warning", 396 | "simulation_model_issue": "ignore", 397 | "unannotated": "error", 398 | "unit_value_mismatch": "error", 399 | "unresolved_variable": "error", 400 | "wire_dangling": "error" 401 | } 402 | }, 403 | "libraries": { 404 | "pinned_footprint_libs": [], 405 | "pinned_symbol_libs": [] 406 | }, 407 | "meta": { 408 | "filename": "wii_mainboard.kicad_pro", 409 | "version": 1 410 | }, 411 | "net_settings": { 412 | "classes": [ 413 | { 414 | "bus_width": 12, 415 | "clearance": 0.1524, 416 | "diff_pair_gap": 0.25, 417 | "diff_pair_via_gap": 0.25, 418 | "diff_pair_width": 0.2, 419 | "line_style": 0, 420 | "microvia_diameter": 0.3, 421 | "microvia_drill": 0.1, 422 | "name": "Default", 423 | "pcb_color": "rgba(0, 0, 0, 0.000)", 424 | "schematic_color": "rgba(0, 0, 0, 0.000)", 425 | "track_width": 0.1524, 426 | "via_diameter": 0.7, 427 | "via_drill": 0.3, 428 | "wire_width": 6 429 | }, 430 | { 431 | "bus_width": 12, 432 | "clearance": 0.1778, 433 | "diff_pair_gap": 0.25, 434 | "diff_pair_via_gap": 0.25, 435 | "diff_pair_width": 0.2, 436 | "line_style": 0, 437 | "microvia_diameter": 0.3, 438 | "microvia_drill": 0.1, 439 | "name": "Power", 440 | "pcb_color": "rgba(0, 0, 0, 0.000)", 441 | "schematic_color": "rgba(0, 0, 0, 0.000)", 442 | "track_width": 0.2286, 443 | "via_diameter": 0.7, 444 | "via_drill": 0.3, 445 | "wire_width": 6 446 | } 447 | ], 448 | "meta": { 449 | "version": 3 450 | }, 451 | "net_colors": null, 452 | "netclass_assignments": null, 453 | "netclass_patterns": [ 454 | { 455 | "netclass": "Power", 456 | "pattern": "+3V3" 457 | }, 458 | { 459 | "netclass": "Power", 460 | "pattern": "+1V8" 461 | }, 462 | { 463 | "netclass": "Power", 464 | "pattern": "+5V" 465 | }, 466 | { 467 | "netclass": "Power", 468 | "pattern": "GND" 469 | } 470 | ] 471 | }, 472 | "pcbnew": { 473 | "last_paths": { 474 | "gencad": "", 475 | "idf": "", 476 | "netlist": "", 477 | "specctra_dsn": "", 478 | "step": "", 479 | "vrml": "" 480 | }, 481 | "page_layout_descr_file": "" 482 | }, 483 | "schematic": { 484 | "annotate_start_num": 0, 485 | "drawing": { 486 | "dashed_lines_dash_length_ratio": 12.0, 487 | "dashed_lines_gap_length_ratio": 3.0, 488 | "default_line_thickness": 6.0, 489 | "default_text_size": 50.0, 490 | "field_names": [], 491 | "intersheets_ref_own_page": false, 492 | "intersheets_ref_prefix": "", 493 | "intersheets_ref_short": false, 494 | "intersheets_ref_show": false, 495 | "intersheets_ref_suffix": "", 496 | "junction_size_choice": 3, 497 | "label_size_ratio": 0.375, 498 | "pin_symbol_size": 25.0, 499 | "text_offset_ratio": 0.15 500 | }, 501 | "legacy_lib_dir": "", 502 | "legacy_lib_list": [], 503 | "meta": { 504 | "version": 1 505 | }, 506 | "net_format_name": "", 507 | "page_layout_descr_file": "", 508 | "plot_directory": "production/", 509 | "spice_current_sheet_as_root": false, 510 | "spice_external_command": "spice \"%I\"", 511 | "spice_model_current_sheet_as_root": true, 512 | "spice_save_all_currents": false, 513 | "spice_save_all_voltages": false, 514 | "subpart_first_id": 65, 515 | "subpart_id_separator": 0 516 | }, 517 | "sheets": [ 518 | [ 519 | "eec156f7-c861-41da-80ac-d4327a119bb1", 520 | "" 521 | ] 522 | ], 523 | "text_variables": {} 524 | } 525 | -------------------------------------------------------------------------------- /hardware/wii_flex/wii_flex.kicad_pro: -------------------------------------------------------------------------------- 1 | { 2 | "board": { 3 | "3dviewports": [], 4 | "design_settings": { 5 | "defaults": { 6 | "board_outline_line_width": 0.09999999999999999, 7 | "copper_line_width": 0.19999999999999998, 8 | "copper_text_italic": false, 9 | "copper_text_size_h": 1.5, 10 | "copper_text_size_v": 1.5, 11 | "copper_text_thickness": 0.3, 12 | "copper_text_upright": false, 13 | "courtyard_line_width": 0.049999999999999996, 14 | "dimension_precision": 4, 15 | "dimension_units": 3, 16 | "dimensions": { 17 | "arrow_length": 1270000, 18 | "extension_offset": 500000, 19 | "keep_text_aligned": true, 20 | "suppress_zeroes": false, 21 | "text_position": 0, 22 | "units_format": 1 23 | }, 24 | "fab_line_width": 0.09999999999999999, 25 | "fab_text_italic": false, 26 | "fab_text_size_h": 1.0, 27 | "fab_text_size_v": 1.0, 28 | "fab_text_thickness": 0.15, 29 | "fab_text_upright": false, 30 | "other_line_width": 0.15, 31 | "other_text_italic": false, 32 | "other_text_size_h": 1.0, 33 | "other_text_size_v": 1.0, 34 | "other_text_thickness": 0.15, 35 | "other_text_upright": false, 36 | "pads": { 37 | "drill": 0.4, 38 | "height": 0.75, 39 | "width": 0.75 40 | }, 41 | "silk_line_width": 0.15, 42 | "silk_text_italic": false, 43 | "silk_text_size_h": 1.0, 44 | "silk_text_size_v": 1.0, 45 | "silk_text_thickness": 0.15, 46 | "silk_text_upright": false, 47 | "zones": { 48 | "45_degree_only": false, 49 | "min_clearance": 0.3 50 | } 51 | }, 52 | "diff_pair_dimensions": [ 53 | { 54 | "gap": 0.0, 55 | "via_gap": 0.0, 56 | "width": 0.0 57 | } 58 | ], 59 | "drc_exclusions": [], 60 | "meta": { 61 | "version": 2 62 | }, 63 | "rule_severities": { 64 | "annular_width": "error", 65 | "clearance": "error", 66 | "connection_width": "warning", 67 | "copper_edge_clearance": "error", 68 | "copper_sliver": "warning", 69 | "courtyards_overlap": "error", 70 | "diff_pair_gap_out_of_range": "error", 71 | "diff_pair_uncoupled_length_too_long": "error", 72 | "drill_out_of_range": "error", 73 | "duplicate_footprints": "warning", 74 | "extra_footprint": "warning", 75 | "footprint": "error", 76 | "footprint_type_mismatch": "error", 77 | "hole_clearance": "error", 78 | "hole_near_hole": "error", 79 | "invalid_outline": "error", 80 | "isolated_copper": "warning", 81 | "item_on_disabled_layer": "error", 82 | "items_not_allowed": "error", 83 | "length_out_of_range": "error", 84 | "lib_footprint_issues": "warning", 85 | "lib_footprint_mismatch": "warning", 86 | "malformed_courtyard": "error", 87 | "microvia_drill_out_of_range": "error", 88 | "missing_courtyard": "ignore", 89 | "missing_footprint": "warning", 90 | "net_conflict": "warning", 91 | "npth_inside_courtyard": "ignore", 92 | "padstack": "error", 93 | "pth_inside_courtyard": "ignore", 94 | "shorting_items": "error", 95 | "silk_edge_clearance": "warning", 96 | "silk_over_copper": "warning", 97 | "silk_overlap": "warning", 98 | "skew_out_of_range": "error", 99 | "solder_mask_bridge": "error", 100 | "starved_thermal": "error", 101 | "text_height": "warning", 102 | "text_thickness": "warning", 103 | "through_hole_pad_without_hole": "error", 104 | "too_many_vias": "error", 105 | "track_dangling": "warning", 106 | "track_width": "error", 107 | "tracks_crossing": "error", 108 | "unconnected_items": "error", 109 | "unresolved_variable": "error", 110 | "via_dangling": "warning", 111 | "zones_intersect": "error" 112 | }, 113 | "rules": { 114 | "allow_blind_buried_vias": false, 115 | "allow_microvias": false, 116 | "max_error": 0.005, 117 | "min_clearance": 0.07619999999999999, 118 | "min_connection": 0.07619999999999999, 119 | "min_copper_edge_clearance": 0.3, 120 | "min_hole_clearance": 0.19999999999999998, 121 | "min_hole_to_hole": 0.5, 122 | "min_microvia_diameter": 0.35, 123 | "min_microvia_drill": 0.15, 124 | "min_resolved_spokes": 2, 125 | "min_silk_clearance": 0.0, 126 | "min_text_height": 0.7999999999999999, 127 | "min_text_thickness": 0.08, 128 | "min_through_hole_diameter": 0.15, 129 | "min_track_width": 0.07619999999999999, 130 | "min_via_annular_width": 0.125, 131 | "min_via_diameter": 0.35, 132 | "solder_mask_clearance": 0.0, 133 | "solder_mask_min_width": 0.0, 134 | "solder_mask_to_copper_clearance": 0.0, 135 | "use_height_for_length_calcs": true 136 | }, 137 | "teardrop_options": [ 138 | { 139 | "td_allow_use_two_tracks": true, 140 | "td_curve_segcount": 5, 141 | "td_on_pad_in_zone": false, 142 | "td_onpadsmd": true, 143 | "td_onroundshapesonly": false, 144 | "td_ontrackend": false, 145 | "td_onviapad": true 146 | } 147 | ], 148 | "teardrop_parameters": [ 149 | { 150 | "td_curve_segcount": 0, 151 | "td_height_ratio": 1.0, 152 | "td_length_ratio": 0.5, 153 | "td_maxheight": 2.0, 154 | "td_maxlen": 1.0, 155 | "td_target_name": "td_round_shape", 156 | "td_width_to_size_filter_ratio": 0.9 157 | }, 158 | { 159 | "td_curve_segcount": 0, 160 | "td_height_ratio": 1.0, 161 | "td_length_ratio": 0.5, 162 | "td_maxheight": 2.0, 163 | "td_maxlen": 1.0, 164 | "td_target_name": "td_rect_shape", 165 | "td_width_to_size_filter_ratio": 0.9 166 | }, 167 | { 168 | "td_curve_segcount": 0, 169 | "td_height_ratio": 1.0, 170 | "td_length_ratio": 0.5, 171 | "td_maxheight": 2.0, 172 | "td_maxlen": 1.0, 173 | "td_target_name": "td_track_end", 174 | "td_width_to_size_filter_ratio": 0.9 175 | } 176 | ], 177 | "track_widths": [ 178 | 0.0 179 | ], 180 | "via_dimensions": [ 181 | { 182 | "diameter": 0.0, 183 | "drill": 0.0 184 | } 185 | ], 186 | "zones_allow_external_fillets": false, 187 | "zones_use_no_outline": true 188 | }, 189 | "layer_presets": [], 190 | "viewports": [] 191 | }, 192 | "boards": [], 193 | "cvpcb": { 194 | "equivalence_files": [] 195 | }, 196 | "erc": { 197 | "erc_exclusions": [], 198 | "meta": { 199 | "version": 0 200 | }, 201 | "pin_map": [ 202 | [ 203 | 0, 204 | 0, 205 | 0, 206 | 0, 207 | 0, 208 | 0, 209 | 1, 210 | 0, 211 | 0, 212 | 0, 213 | 0, 214 | 2 215 | ], 216 | [ 217 | 0, 218 | 2, 219 | 0, 220 | 1, 221 | 0, 222 | 0, 223 | 1, 224 | 0, 225 | 2, 226 | 2, 227 | 2, 228 | 2 229 | ], 230 | [ 231 | 0, 232 | 0, 233 | 0, 234 | 0, 235 | 0, 236 | 0, 237 | 1, 238 | 0, 239 | 1, 240 | 0, 241 | 1, 242 | 2 243 | ], 244 | [ 245 | 0, 246 | 1, 247 | 0, 248 | 0, 249 | 0, 250 | 0, 251 | 1, 252 | 1, 253 | 2, 254 | 1, 255 | 1, 256 | 2 257 | ], 258 | [ 259 | 0, 260 | 0, 261 | 0, 262 | 0, 263 | 0, 264 | 0, 265 | 1, 266 | 0, 267 | 0, 268 | 0, 269 | 0, 270 | 2 271 | ], 272 | [ 273 | 0, 274 | 0, 275 | 0, 276 | 0, 277 | 0, 278 | 0, 279 | 0, 280 | 0, 281 | 0, 282 | 0, 283 | 0, 284 | 2 285 | ], 286 | [ 287 | 1, 288 | 1, 289 | 1, 290 | 1, 291 | 1, 292 | 0, 293 | 1, 294 | 1, 295 | 1, 296 | 1, 297 | 1, 298 | 2 299 | ], 300 | [ 301 | 0, 302 | 0, 303 | 0, 304 | 1, 305 | 0, 306 | 0, 307 | 1, 308 | 0, 309 | 0, 310 | 0, 311 | 0, 312 | 2 313 | ], 314 | [ 315 | 0, 316 | 2, 317 | 1, 318 | 2, 319 | 0, 320 | 0, 321 | 1, 322 | 0, 323 | 2, 324 | 2, 325 | 2, 326 | 2 327 | ], 328 | [ 329 | 0, 330 | 2, 331 | 0, 332 | 1, 333 | 0, 334 | 0, 335 | 1, 336 | 0, 337 | 2, 338 | 0, 339 | 0, 340 | 2 341 | ], 342 | [ 343 | 0, 344 | 2, 345 | 1, 346 | 1, 347 | 0, 348 | 0, 349 | 1, 350 | 0, 351 | 2, 352 | 0, 353 | 0, 354 | 2 355 | ], 356 | [ 357 | 2, 358 | 2, 359 | 2, 360 | 2, 361 | 2, 362 | 2, 363 | 2, 364 | 2, 365 | 2, 366 | 2, 367 | 2, 368 | 2 369 | ] 370 | ], 371 | "rule_severities": { 372 | "bus_definition_conflict": "error", 373 | "bus_entry_needed": "error", 374 | "bus_to_bus_conflict": "error", 375 | "bus_to_net_conflict": "error", 376 | "conflicting_netclasses": "error", 377 | "different_unit_footprint": "error", 378 | "different_unit_net": "error", 379 | "duplicate_reference": "error", 380 | "duplicate_sheet_names": "error", 381 | "endpoint_off_grid": "warning", 382 | "extra_units": "error", 383 | "global_label_dangling": "warning", 384 | "hier_label_mismatch": "error", 385 | "label_dangling": "error", 386 | "lib_symbol_issues": "warning", 387 | "missing_bidi_pin": "warning", 388 | "missing_input_pin": "warning", 389 | "missing_power_pin": "error", 390 | "missing_unit": "warning", 391 | "multiple_net_names": "warning", 392 | "net_not_bus_member": "warning", 393 | "no_connect_connected": "warning", 394 | "no_connect_dangling": "warning", 395 | "pin_not_connected": "error", 396 | "pin_not_driven": "error", 397 | "pin_to_pin": "warning", 398 | "power_pin_not_driven": "error", 399 | "similar_labels": "warning", 400 | "simulation_model_issue": "ignore", 401 | "unannotated": "error", 402 | "unit_value_mismatch": "error", 403 | "unresolved_variable": "error", 404 | "wire_dangling": "error" 405 | } 406 | }, 407 | "libraries": { 408 | "pinned_footprint_libs": [], 409 | "pinned_symbol_libs": [] 410 | }, 411 | "meta": { 412 | "filename": "wii_dvi.kicad_pro", 413 | "version": 1 414 | }, 415 | "net_settings": { 416 | "classes": [ 417 | { 418 | "bus_width": 12, 419 | "clearance": 0.15, 420 | "diff_pair_gap": 0.25, 421 | "diff_pair_via_gap": 0.25, 422 | "diff_pair_width": 0.2, 423 | "line_style": 0, 424 | "microvia_diameter": 0.3, 425 | "microvia_drill": 0.1, 426 | "name": "Default", 427 | "pcb_color": "rgba(0, 0, 0, 0.000)", 428 | "schematic_color": "rgba(0, 0, 0, 0.000)", 429 | "track_width": 0.2, 430 | "via_diameter": 0.55, 431 | "via_drill": 0.3, 432 | "wire_width": 6 433 | }, 434 | { 435 | "bus_width": 12, 436 | "clearance": 0.25, 437 | "diff_pair_gap": 0.25, 438 | "diff_pair_via_gap": 0.25, 439 | "diff_pair_width": 0.2, 440 | "line_style": 0, 441 | "microvia_diameter": 0.3, 442 | "microvia_drill": 0.1, 443 | "name": "Power", 444 | "pcb_color": "rgba(0, 0, 0, 0.000)", 445 | "schematic_color": "rgba(0, 0, 0, 0.000)", 446 | "track_width": 0.4, 447 | "via_diameter": 0.55, 448 | "via_drill": 0.3, 449 | "wire_width": 6 450 | } 451 | ], 452 | "meta": { 453 | "version": 3 454 | }, 455 | "net_colors": null, 456 | "netclass_assignments": null, 457 | "netclass_patterns": [ 458 | { 459 | "netclass": "Power", 460 | "pattern": "+1V8" 461 | } 462 | ] 463 | }, 464 | "pcbnew": { 465 | "last_paths": { 466 | "gencad": "", 467 | "idf": "", 468 | "netlist": "", 469 | "specctra_dsn": "", 470 | "step": "", 471 | "vrml": "" 472 | }, 473 | "page_layout_descr_file": "" 474 | }, 475 | "schematic": { 476 | "annotate_start_num": 0, 477 | "drawing": { 478 | "dashed_lines_dash_length_ratio": 12.0, 479 | "dashed_lines_gap_length_ratio": 3.0, 480 | "default_line_thickness": 6.0, 481 | "default_text_size": 50.0, 482 | "field_names": [], 483 | "intersheets_ref_own_page": false, 484 | "intersheets_ref_prefix": "", 485 | "intersheets_ref_short": false, 486 | "intersheets_ref_show": false, 487 | "intersheets_ref_suffix": "", 488 | "junction_size_choice": 3, 489 | "label_size_ratio": 0.375, 490 | "pin_symbol_size": 25.0, 491 | "text_offset_ratio": 0.15 492 | }, 493 | "legacy_lib_dir": "", 494 | "legacy_lib_list": [], 495 | "meta": { 496 | "version": 1 497 | }, 498 | "net_format_name": "", 499 | "ngspice": { 500 | "fix_include_paths": true, 501 | "fix_passive_vals": false, 502 | "meta": { 503 | "version": 0 504 | }, 505 | "model_mode": 0, 506 | "workbook_filename": "" 507 | }, 508 | "page_layout_descr_file": "", 509 | "plot_directory": "", 510 | "spice_adjust_passive_values": false, 511 | "spice_current_sheet_as_root": false, 512 | "spice_external_command": "spice \"%I\"", 513 | "spice_model_current_sheet_as_root": true, 514 | "spice_save_all_currents": false, 515 | "spice_save_all_voltages": false, 516 | "subpart_first_id": 65, 517 | "subpart_id_separator": 0 518 | }, 519 | "sheets": [ 520 | [ 521 | "8f1eb5fd-9363-45fd-bb70-da1394710235", 522 | "" 523 | ] 524 | ], 525 | "text_variables": {} 526 | } 527 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2024 xtreme8000 3 | 4 | This file is part of picoAVE. 5 | 6 | picoAVE is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | picoAVE is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with picoAVE. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include "hardware/structs/bus_ctrl.h" 24 | #include "hardware/vreg.h" 25 | #include "pico/multicore.h" 26 | #include "pico/platform.h" 27 | #include "pico/stdlib.h" 28 | #include "pico/util/queue.h" 29 | 30 | #include "config.h" 31 | #include "font.h" 32 | #include "frame.h" 33 | #include "gpu_input.h" 34 | #include "mem_pool.h" 35 | #include "packets.h" 36 | #include "str_builder.h" 37 | #include "tmds_encode.h" 38 | #include "utils.h" 39 | #include "video_output.h" 40 | 41 | uint32_t tmds_image_00h[FRAME_BUFFER_WIDTH / 2]; 42 | uint32_t tmds_image_10h[FRAME_BUFFER_WIDTH / 2]; 43 | uint32_t tmds_image_80h[FRAME_BUFFER_WIDTH / 2]; 44 | 45 | struct mem_pool pool_packets; 46 | struct mem_pool pool_video; 47 | struct mem_pool pool_audio; 48 | 49 | queue_t queue_test; 50 | queue_t queue_test_audio; 51 | 52 | void thread1(void); 53 | void thread2(void); 54 | void encode_video_isr(void); 55 | 56 | static void* alloc_video() { 57 | struct tmds_data3* obj = malloc(sizeof(struct tmds_data3)); 58 | obj->type = TYPE_VIDEO; 59 | obj->encode_offset = 0; 60 | obj->encode_length = 0; 61 | obj->length = FRAME_BUFFER_WIDTH / 2; 62 | obj->ptr[0] = tmds_image_00h; 63 | obj->ptr[1] = malloc(obj->length * sizeof(uint32_t)); 64 | obj->ptr[2] = malloc(obj->length * sizeof(uint32_t)); 65 | return obj; 66 | } 67 | 68 | static void* alloc_audio() { 69 | return malloc(sizeof(struct audio_data)); 70 | } 71 | 72 | static void* alloc_packet() { 73 | struct tmds_data3* obj = malloc(sizeof(struct tmds_data3)); 74 | obj->type = TYPE_PACKET; 75 | obj->length = (FRAME_WIDTH - FRAME_BUFFER_WIDTH) / 2; 76 | obj->ptr[0] = malloc(obj->length * sizeof(uint32_t)); 77 | obj->ptr[1] = malloc(obj->length * sizeof(uint32_t)); 78 | obj->ptr[2] = malloc(obj->length * sizeof(uint32_t)); 79 | 80 | tmds_encode_sync(obj->length * 2, true, obj->ptr[0], obj->ptr[1], 81 | obj->ptr[2]); 82 | return obj; 83 | } 84 | 85 | int main() { 86 | // set_sys_clock_pll(336 * 1000 * 1000, 7, 6); // 8 MHz 87 | vreg_set_voltage(VREG_VOLTAGE_1_20); 88 | sleep_ms(10); 89 | set_sys_clock_khz(FRAME_CLOCK, true); 90 | sleep_ms(10); 91 | 92 | // Looks like main memory has high congestion in hotspots, this gives 93 | // DMA accesses the highest priority to keep all TMDS data channels in sync. 94 | // Additonally most interrupt code + data has been moved to scratch memory. 95 | bus_ctrl_hw->priority 96 | = BUSCTRL_BUS_PRIORITY_DMA_W_BITS | BUSCTRL_BUS_PRIORITY_DMA_R_BITS; 97 | 98 | gpio_init(BOARD_LED0); 99 | gpio_set_dir(BOARD_LED0, GPIO_OUT); 100 | 101 | gpio_init(BOARD_LED1); 102 | gpio_set_dir(BOARD_LED1, GPIO_OUT); 103 | gpio_set_mask(1 << BOARD_LED1); 104 | 105 | for(size_t k = 0; k < FRAME_BUFFER_WIDTH / 2; k++) { 106 | tmds_image_00h[k] = 0xffd00; 107 | tmds_image_10h[k] = 0x7c1f0; 108 | tmds_image_80h[k] = tmds_symbols_cbcr[4]; 109 | } 110 | 111 | tmds_encode_sync_video(tmds_image_00h, tmds_image_10h, tmds_image_80h); 112 | 113 | mem_pool_create(&pool_video, alloc_video, 16, NULL); 114 | mem_pool_create(&pool_audio, alloc_audio, 8, NULL); 115 | mem_pool_create(&pool_packets, alloc_packet, 16, NULL); 116 | queue_init(&queue_test, sizeof(struct tmds_data3*), 117 | mem_pool_capacity(&pool_video)); 118 | queue_init(&queue_test_audio, sizeof(struct audio_data*), 119 | mem_pool_capacity(&pool_audio)); 120 | 121 | tmds_encode_init(); 122 | tmds_encode_setup(); 123 | packets_init(); 124 | video_output_init((uint[]) {BOARD_TMDS_0, BOARD_TMDS_1, BOARD_TMDS_2}, 125 | BOARD_TMDS_CLK, &pool_video, &pool_packets); 126 | 127 | multicore_launch_core1(thread2); 128 | 129 | irq_set_exclusive_handler(SIO_IRQ_PROC0, encode_video_isr); 130 | irq_set_enabled(SIO_IRQ_PROC0, true); 131 | 132 | thread1(); 133 | 134 | return 0; 135 | } 136 | 137 | static size_t cnt = 0; 138 | 139 | void CORE0_CODE encode_video_isr() { 140 | multicore_fifo_drain(); 141 | multicore_fifo_clear_irq(); 142 | 143 | struct tmds_data3* obj; 144 | while(queue_try_remove(&queue_test, &obj)) { 145 | if(obj->encode_length > 0) 146 | tmds_encode_y1y2(obj->ptr[1] + obj->encode_offset, 147 | obj->encode_length, 148 | obj->ptr[1] + obj->encode_offset); 149 | 150 | video_output_submit(obj); 151 | 152 | if((++cnt) == 15 * FRAME_VIS_HEIGHT) { 153 | cnt = 0; 154 | gpio_xor_mask(1 << BOARD_LED0); 155 | } 156 | } 157 | } 158 | 159 | void CORE0_CODE thread1() { 160 | video_output_start(); 161 | 162 | while(1) { 163 | struct audio_data* frame; 164 | queue_remove_blocking(&queue_test_audio, &frame); 165 | 166 | #ifndef DVI_ONLY 167 | for(size_t idx = 0; idx < AUDIO_FRAME_LENGTH; idx += 4) { 168 | struct tmds_data3* obj = mem_pool_alloc(&pool_packets); 169 | 170 | packets_encode_audio(frame->audio_data + idx, idx, false, true, 171 | obj->ptr[0] + FRAME_H_PORCH_FRONT / 2, 172 | obj->ptr[1] + FRAME_H_PORCH_FRONT / 2, 173 | obj->ptr[2] + FRAME_H_PORCH_FRONT / 2); 174 | 175 | video_output_submit(obj); 176 | } 177 | #endif 178 | 179 | uint32_t samplerate = frame->samplerate; 180 | mem_pool_free(&pool_audio, frame); 181 | 182 | if(samplerate > 0) 183 | video_output_set_audio_info(samplerate); 184 | } 185 | } 186 | 187 | #define BLANK_MASK 0xF000F000 // check any Y >= 16 188 | 189 | bool CORE1_CODE advance_input(size_t* idx, struct gpu_data** data, 190 | size_t amount) { 191 | *idx += amount; 192 | 193 | while(*idx >= (*data)->length) { 194 | *idx -= (*data)->length; 195 | gpu_input_release(*data); 196 | 197 | struct gpu_data* res = gpu_input_receive(); 198 | *data = res; 199 | 200 | if(res->data_skipped) 201 | return false; 202 | } 203 | 204 | return true; 205 | } 206 | 207 | bool CORE1_CODE find_image_start(struct gpu_data** data, size_t* start, 208 | size_t* width) { 209 | struct gpu_data* current_data = gpu_input_receive(); 210 | 211 | size_t video_start, video_end; 212 | size_t k = 0; 213 | 214 | while(1) { 215 | bool blanking = (current_data->ptr[k] & BLANK_MASK) == 0; 216 | 217 | if(unlikely(blanking)) 218 | break; 219 | 220 | if(unlikely((++k) >= current_data->length)) { 221 | gpu_input_release(current_data); 222 | return false; 223 | } 224 | } 225 | 226 | while(1) { 227 | bool blanking = (current_data->ptr[k] & BLANK_MASK) == 0; 228 | 229 | if(unlikely(!blanking)) { 230 | video_start = k; 231 | break; 232 | } 233 | 234 | if(unlikely((++k) >= current_data->length)) { 235 | gpu_input_release(current_data); 236 | return false; 237 | } 238 | } 239 | 240 | while(1) { 241 | bool blanking = (current_data->ptr[k] & BLANK_MASK) == 0; 242 | 243 | if(unlikely(blanking)) { 244 | video_end = k; 245 | break; 246 | } 247 | 248 | if(unlikely((++k) >= current_data->length)) { 249 | gpu_input_release(current_data); 250 | return false; 251 | } 252 | } 253 | 254 | *start = video_start; 255 | *width = min_n(video_end - video_start, FRAME_VIS_WIDTH / 2); 256 | *data = current_data; 257 | return true; 258 | } 259 | 260 | struct gpu_sync_state { 261 | size_t video_xstart; 262 | size_t video_vstart, video_vend; 263 | size_t video_width, video_width_padded; 264 | struct gpu_data* current_data; 265 | size_t current_idx; 266 | char msg[32]; 267 | int msg_frames_visible; 268 | }; 269 | 270 | bool CORE1_CODE gpu_sync_video(struct gpu_sync_state* state) { 271 | size_t video_objs_length = mem_pool_capacity(&pool_video); 272 | struct tmds_data3* video_objs[video_objs_length]; 273 | 274 | for(size_t k = 0; k < video_objs_length; k++) { 275 | video_objs[k] = mem_pool_alloc(&pool_video); 276 | memcpy(video_objs[k]->ptr[1], tmds_image_10h, sizeof(tmds_image_10h)); 277 | memcpy(video_objs[k]->ptr[2], tmds_image_80h, sizeof(tmds_image_80h)); 278 | } 279 | 280 | for(size_t k = 0; k < video_objs_length; k++) 281 | mem_pool_free(&pool_video, video_objs[k]); 282 | 283 | size_t current_idx, video_width; 284 | struct gpu_data* current_data; 285 | bool shifted = false; 286 | while(1) { 287 | gpu_input_drain(shifted); 288 | 289 | if(find_image_start(¤t_data, ¤t_idx, &video_width)) { 290 | uint32_t pixels = current_data->ptr[current_idx]; 291 | bool blanking0 = ((pixels >> 24) & 0xF0) == 0; 292 | bool blanking1 = ((pixels >> 8) & 0xF0) == 0; 293 | 294 | if(!blanking0 && !blanking1) { 295 | break; 296 | } else { 297 | shifted = !shifted; 298 | gpu_input_release(current_data); 299 | } 300 | } 301 | } 302 | 303 | bool success = true; 304 | bool prev_blank = false; 305 | size_t loop_counter = 0; 306 | 307 | while(1) { 308 | bool blanking = (current_data->ptr[current_idx] & BLANK_MASK) == 0; 309 | 310 | if(prev_blank && !blanking) 311 | break; 312 | 313 | prev_blank = blanking; 314 | 315 | if(!advance_input(¤t_idx, ¤t_data, FRAME_WIDTH / 2) 316 | || loop_counter >= FRAME_HEIGHT * 4) { 317 | success = false; 318 | break; 319 | } 320 | 321 | loop_counter++; 322 | } 323 | 324 | size_t video_height = 0; 325 | 326 | while(video_height < FRAME_VIS_HEIGHT) { 327 | bool blanking = (current_data->ptr[current_idx] & BLANK_MASK) == 0; 328 | 329 | if(blanking) 330 | break; 331 | 332 | if(!advance_input(¤t_idx, ¤t_data, FRAME_WIDTH / 2)) { 333 | success = false; 334 | break; 335 | } 336 | 337 | video_height++; 338 | } 339 | 340 | if(!advance_input(¤t_idx, ¤t_data, 341 | (FRAME_HEIGHT - video_height) * FRAME_WIDTH / 2)) 342 | success = false; 343 | 344 | static_assert(FRAME_VIS_WIDTH / 2 % 3 == 0); 345 | size_t video_width_padded = (video_width + 2) / 3 * 3; 346 | size_t video_xstart = (FRAME_VIS_WIDTH / 2 - video_width) / 2; 347 | 348 | if(video_xstart + video_width_padded > FRAME_VIS_WIDTH / 2) 349 | video_xstart = 0; 350 | 351 | size_t video_vstart = (FRAME_VIS_HEIGHT - video_height) / 2; 352 | size_t video_vend = video_height + video_vstart; 353 | 354 | state->video_xstart = video_xstart; 355 | state->video_vstart = video_vstart; 356 | state->video_vend = video_vend; 357 | state->video_width = video_width; 358 | state->video_width_padded = video_width_padded; 359 | state->current_data = current_data; 360 | state->current_idx = current_idx; 361 | 362 | str_finish(str_append( 363 | str_uint(str_char(str_uint(state->msg, video_width * 2), 'x'), 364 | video_height), 365 | #ifdef GIT_COMMIT_HASH 366 | "p [" PROJECT_NAME " " GIT_COMMIT_HASH "]" 367 | #else 368 | "p [" PROJECT_NAME " " PROJECT_VERSION "]" 369 | #endif 370 | )); 371 | state->msg_frames_visible = 60 * 10; 372 | 373 | return success; 374 | } 375 | 376 | struct tmds_data3 CORE0_DATA empty_line[2] = { 377 | { 378 | .vsync = false, 379 | .type = TYPE_CONST, 380 | .encode_length = 0, 381 | .length = FRAME_BUFFER_WIDTH / 2, 382 | .ptr = {tmds_image_00h, tmds_image_10h, tmds_image_80h}, 383 | }, 384 | { 385 | .vsync = true, 386 | .type = TYPE_CONST, 387 | .encode_length = 0, 388 | .length = FRAME_BUFFER_WIDTH / 2, 389 | .ptr = {tmds_image_00h, tmds_image_10h, tmds_image_80h}, 390 | }, 391 | }; 392 | 393 | void CORE1_CODE thread2() { 394 | tmds_encode_setup(); 395 | 396 | // TODO: only 32 because of an overflow during following sync scan 397 | gpu_input_init(15, FRAME_WIDTH / 2 * 4, BOARD_VIDEO_BASE, &pool_audio, 398 | &queue_test_audio, BOARD_AUDIO_BASE, BOARD_AUDIO_WS); 399 | gpu_input_start(); 400 | 401 | struct gpu_sync_state gpu_sync; 402 | int needs_resync_frames = 0; 403 | 404 | while(!gpu_sync_video(&gpu_sync)) 405 | tight_loop_contents(); 406 | 407 | while(1) { 408 | bool needs_resync = false; 409 | 410 | for(size_t k = gpu_sync.video_vstart; k < gpu_sync.video_vend; k++) { 411 | struct tmds_data3* obj = mem_pool_alloc(&pool_video); 412 | obj->vsync = k == 0; 413 | obj->encode_offset 414 | = FRAME_BUFFER_OFFSET / 2 + gpu_sync.video_xstart; 415 | obj->encode_length = gpu_sync.video_width_padded; 416 | 417 | bool blanking1 = (gpu_sync.current_data->ptr[gpu_sync.current_idx] 418 | & BLANK_MASK) 419 | == 0; 420 | if(blanking1) 421 | needs_resync = true; 422 | 423 | size_t line_idx = 0; 424 | 425 | if(gpu_sync.msg_frames_visible > 0 426 | && k < gpu_sync.video_vstart + FONT_CHAR_HEIGHT) { 427 | size_t width 428 | = font_encode(gpu_sync.msg, k - gpu_sync.video_vstart, 429 | obj->ptr[1] + obj->encode_offset); 430 | 431 | line_idx += width; 432 | if(!advance_input(&gpu_sync.current_idx, &gpu_sync.current_data, 433 | width)) 434 | needs_resync = true; 435 | } 436 | 437 | while(line_idx < gpu_sync.video_width) { 438 | size_t can_take = min_n(gpu_sync.video_width - line_idx, 439 | gpu_sync.current_data->length 440 | - gpu_sync.current_idx); 441 | memcpy(obj->ptr[1] + obj->encode_offset + line_idx, 442 | gpu_sync.current_data->ptr + gpu_sync.current_idx, 443 | can_take * sizeof(uint32_t)); 444 | 445 | line_idx += can_take; 446 | if(!advance_input(&gpu_sync.current_idx, &gpu_sync.current_data, 447 | can_take)) 448 | needs_resync = true; 449 | } 450 | 451 | while(line_idx < gpu_sync.video_width_padded) 452 | obj->ptr[1][obj->encode_offset + line_idx++] = 0x10801080; 453 | 454 | size_t bias = tmds_encode_cbcr(obj->ptr[1] + obj->encode_offset, 455 | gpu_sync.video_width_padded, 456 | obj->ptr[2] + obj->encode_offset); 457 | 458 | // finish bias at 0 for cbcr lane 459 | // not required for y1y2, because symbol 0x10 leaves bias unchanged 460 | if(obj->encode_offset + gpu_sync.video_width_padded < obj->length) 461 | obj->ptr[2][obj->encode_offset + gpu_sync.video_width_padded] 462 | = tmds_symbols_cbcr[bias]; 463 | 464 | queue_add_blocking(&queue_test, &obj); 465 | multicore_fifo_push_blocking(0); 466 | 467 | bool blanking2 = (gpu_sync.current_data->ptr[gpu_sync.current_idx] 468 | & BLANK_MASK) 469 | == 0; 470 | if(!blanking2) 471 | needs_resync = true; 472 | 473 | if(!advance_input(&gpu_sync.current_idx, &gpu_sync.current_data, 474 | FRAME_WIDTH / 2 - gpu_sync.video_width)) 475 | needs_resync = true; 476 | } 477 | 478 | for(size_t k = gpu_sync.video_vend; k < FRAME_VIS_HEIGHT; k++) { 479 | struct tmds_data3* obj = empty_line + 0; 480 | queue_add_blocking(&queue_test, &obj); 481 | multicore_fifo_push_blocking(0); 482 | 483 | bool blanking = (gpu_sync.current_data->ptr[gpu_sync.current_idx] 484 | & BLANK_MASK) 485 | == 0; 486 | if(!blanking) 487 | needs_resync = true; 488 | 489 | if(!advance_input(&gpu_sync.current_idx, &gpu_sync.current_data, 490 | FRAME_WIDTH / 2)) 491 | needs_resync = true; 492 | } 493 | 494 | for(size_t k = 0; k < FRAME_V_BLANK; k++) { 495 | bool blanking = (gpu_sync.current_data->ptr[gpu_sync.current_idx] 496 | & BLANK_MASK) 497 | == 0; 498 | if(!blanking) 499 | needs_resync = true; 500 | 501 | if(!advance_input(&gpu_sync.current_idx, &gpu_sync.current_data, 502 | FRAME_WIDTH / 2)) 503 | needs_resync = true; 504 | } 505 | 506 | for(size_t k = 0; k < gpu_sync.video_vstart; k++) { 507 | struct tmds_data3* obj = empty_line + ((k == 0) ? 1 : 0); 508 | queue_add_blocking(&queue_test, &obj); 509 | multicore_fifo_push_blocking(0); 510 | 511 | bool blanking = (gpu_sync.current_data->ptr[gpu_sync.current_idx] 512 | & BLANK_MASK) 513 | == 0; 514 | if(!blanking) 515 | needs_resync = true; 516 | 517 | if(!advance_input(&gpu_sync.current_idx, &gpu_sync.current_data, 518 | FRAME_WIDTH / 2)) 519 | needs_resync = true; 520 | } 521 | 522 | if(gpu_sync.msg_frames_visible > 0) 523 | gpu_sync.msg_frames_visible--; 524 | 525 | if(needs_resync) 526 | needs_resync_frames++; 527 | 528 | if(needs_resync_frames >= 60) { 529 | needs_resync_frames = 0; 530 | gpu_input_release(gpu_sync.current_data); 531 | 532 | while(!gpu_sync_video(&gpu_sync)) 533 | tight_loop_contents(); 534 | } 535 | } 536 | } -------------------------------------------------------------------------------- /hardware/hdmi_pcb/wii_hdmi_pcb.kicad_pro: -------------------------------------------------------------------------------- 1 | { 2 | "board": { 3 | "3dviewports": [], 4 | "design_settings": { 5 | "defaults": { 6 | "board_outline_line_width": 0.15, 7 | "copper_line_width": 0.19999999999999998, 8 | "copper_text_italic": false, 9 | "copper_text_size_h": 1.5, 10 | "copper_text_size_v": 1.5, 11 | "copper_text_thickness": 0.3, 12 | "copper_text_upright": false, 13 | "courtyard_line_width": 0.049999999999999996, 14 | "dimension_precision": 4, 15 | "dimension_units": 3, 16 | "dimensions": { 17 | "arrow_length": 1270000, 18 | "extension_offset": 500000, 19 | "keep_text_aligned": true, 20 | "suppress_zeroes": false, 21 | "text_position": 0, 22 | "units_format": 1 23 | }, 24 | "fab_line_width": 0.09999999999999999, 25 | "fab_text_italic": false, 26 | "fab_text_size_h": 1.0, 27 | "fab_text_size_v": 1.0, 28 | "fab_text_thickness": 0.15, 29 | "fab_text_upright": false, 30 | "other_line_width": 0.09999999999999999, 31 | "other_text_italic": false, 32 | "other_text_size_h": 1.0, 33 | "other_text_size_v": 1.0, 34 | "other_text_thickness": 0.15, 35 | "other_text_upright": false, 36 | "pads": { 37 | "drill": 1.0, 38 | "height": 1.0, 39 | "width": 1.0 40 | }, 41 | "silk_line_width": 0.15, 42 | "silk_text_italic": false, 43 | "silk_text_size_h": 1.0, 44 | "silk_text_size_v": 1.0, 45 | "silk_text_thickness": 0.15, 46 | "silk_text_upright": false, 47 | "zones": { 48 | "min_clearance": 0.175 49 | } 50 | }, 51 | "diff_pair_dimensions": [ 52 | { 53 | "gap": 0.0, 54 | "via_gap": 0.0, 55 | "width": 0.0 56 | } 57 | ], 58 | "drc_exclusions": [], 59 | "meta": { 60 | "filename": "board_design_settings.json", 61 | "version": 2 62 | }, 63 | "rule_severities": { 64 | "annular_width": "error", 65 | "clearance": "error", 66 | "connection_width": "warning", 67 | "copper_edge_clearance": "error", 68 | "copper_sliver": "warning", 69 | "courtyards_overlap": "error", 70 | "diff_pair_gap_out_of_range": "error", 71 | "diff_pair_uncoupled_length_too_long": "error", 72 | "drill_out_of_range": "error", 73 | "duplicate_footprints": "warning", 74 | "extra_footprint": "warning", 75 | "footprint": "error", 76 | "footprint_type_mismatch": "ignore", 77 | "hole_clearance": "error", 78 | "hole_near_hole": "error", 79 | "invalid_outline": "error", 80 | "isolated_copper": "warning", 81 | "item_on_disabled_layer": "error", 82 | "items_not_allowed": "error", 83 | "length_out_of_range": "error", 84 | "lib_footprint_issues": "warning", 85 | "lib_footprint_mismatch": "warning", 86 | "malformed_courtyard": "error", 87 | "microvia_drill_out_of_range": "error", 88 | "missing_courtyard": "ignore", 89 | "missing_footprint": "warning", 90 | "net_conflict": "warning", 91 | "npth_inside_courtyard": "ignore", 92 | "padstack": "warning", 93 | "pth_inside_courtyard": "ignore", 94 | "shorting_items": "error", 95 | "silk_edge_clearance": "warning", 96 | "silk_over_copper": "warning", 97 | "silk_overlap": "ignore", 98 | "skew_out_of_range": "error", 99 | "solder_mask_bridge": "error", 100 | "starved_thermal": "error", 101 | "text_height": "warning", 102 | "text_thickness": "warning", 103 | "through_hole_pad_without_hole": "error", 104 | "too_many_vias": "error", 105 | "track_dangling": "warning", 106 | "track_width": "error", 107 | "tracks_crossing": "error", 108 | "unconnected_items": "error", 109 | "unresolved_variable": "error", 110 | "via_dangling": "warning", 111 | "zones_intersect": "error" 112 | }, 113 | "rules": { 114 | "max_error": 0.005, 115 | "min_clearance": 0.0, 116 | "min_connection": 0.0, 117 | "min_copper_edge_clearance": 0.3, 118 | "min_hole_clearance": 0.25, 119 | "min_hole_to_hole": 0.25, 120 | "min_microvia_diameter": 0.19999999999999998, 121 | "min_microvia_drill": 0.09999999999999999, 122 | "min_resolved_spokes": 2, 123 | "min_silk_clearance": 0.0, 124 | "min_text_height": 0.7999999999999999, 125 | "min_text_thickness": 0.08, 126 | "min_through_hole_diameter": 0.3, 127 | "min_track_width": 0.15, 128 | "min_via_annular_width": 0.09999999999999999, 129 | "min_via_diameter": 0.39999999999999997, 130 | "solder_mask_to_copper_clearance": 0.005, 131 | "use_height_for_length_calcs": true 132 | }, 133 | "teardrop_options": [ 134 | { 135 | "td_allow_use_two_tracks": true, 136 | "td_curve_segcount": 5, 137 | "td_on_pad_in_zone": false, 138 | "td_onpadsmd": true, 139 | "td_onroundshapesonly": false, 140 | "td_ontrackend": false, 141 | "td_onviapad": true 142 | } 143 | ], 144 | "teardrop_parameters": [ 145 | { 146 | "td_curve_segcount": 0, 147 | "td_height_ratio": 1.0, 148 | "td_length_ratio": 0.5, 149 | "td_maxheight": 2.0, 150 | "td_maxlen": 1.0, 151 | "td_target_name": "td_round_shape", 152 | "td_width_to_size_filter_ratio": 0.9 153 | }, 154 | { 155 | "td_curve_segcount": 0, 156 | "td_height_ratio": 1.0, 157 | "td_length_ratio": 0.5, 158 | "td_maxheight": 2.0, 159 | "td_maxlen": 1.0, 160 | "td_target_name": "td_rect_shape", 161 | "td_width_to_size_filter_ratio": 0.9 162 | }, 163 | { 164 | "td_curve_segcount": 0, 165 | "td_height_ratio": 1.0, 166 | "td_length_ratio": 0.5, 167 | "td_maxheight": 2.0, 168 | "td_maxlen": 1.0, 169 | "td_target_name": "td_track_end", 170 | "td_width_to_size_filter_ratio": 0.9 171 | } 172 | ], 173 | "track_widths": [ 174 | 0.0, 175 | 0.15 176 | ], 177 | "via_dimensions": [ 178 | { 179 | "diameter": 0.0, 180 | "drill": 0.0 181 | } 182 | ], 183 | "zones_allow_external_fillets": false 184 | }, 185 | "layer_presets": [], 186 | "viewports": [] 187 | }, 188 | "boards": [], 189 | "cvpcb": { 190 | "equivalence_files": [] 191 | }, 192 | "erc": { 193 | "erc_exclusions": [], 194 | "meta": { 195 | "version": 0 196 | }, 197 | "pin_map": [ 198 | [ 199 | 0, 200 | 0, 201 | 0, 202 | 0, 203 | 0, 204 | 0, 205 | 1, 206 | 0, 207 | 0, 208 | 0, 209 | 0, 210 | 2 211 | ], 212 | [ 213 | 0, 214 | 2, 215 | 0, 216 | 1, 217 | 0, 218 | 0, 219 | 1, 220 | 0, 221 | 2, 222 | 2, 223 | 2, 224 | 2 225 | ], 226 | [ 227 | 0, 228 | 0, 229 | 0, 230 | 0, 231 | 0, 232 | 0, 233 | 1, 234 | 0, 235 | 1, 236 | 0, 237 | 1, 238 | 2 239 | ], 240 | [ 241 | 0, 242 | 1, 243 | 0, 244 | 0, 245 | 0, 246 | 0, 247 | 1, 248 | 1, 249 | 2, 250 | 1, 251 | 1, 252 | 2 253 | ], 254 | [ 255 | 0, 256 | 0, 257 | 0, 258 | 0, 259 | 0, 260 | 0, 261 | 1, 262 | 0, 263 | 0, 264 | 0, 265 | 0, 266 | 2 267 | ], 268 | [ 269 | 0, 270 | 0, 271 | 0, 272 | 0, 273 | 0, 274 | 0, 275 | 0, 276 | 0, 277 | 0, 278 | 0, 279 | 0, 280 | 2 281 | ], 282 | [ 283 | 1, 284 | 1, 285 | 1, 286 | 1, 287 | 1, 288 | 0, 289 | 1, 290 | 1, 291 | 1, 292 | 1, 293 | 1, 294 | 2 295 | ], 296 | [ 297 | 0, 298 | 0, 299 | 0, 300 | 1, 301 | 0, 302 | 0, 303 | 1, 304 | 0, 305 | 0, 306 | 0, 307 | 0, 308 | 2 309 | ], 310 | [ 311 | 0, 312 | 2, 313 | 1, 314 | 2, 315 | 0, 316 | 0, 317 | 1, 318 | 0, 319 | 2, 320 | 2, 321 | 2, 322 | 2 323 | ], 324 | [ 325 | 0, 326 | 2, 327 | 0, 328 | 1, 329 | 0, 330 | 0, 331 | 1, 332 | 0, 333 | 2, 334 | 0, 335 | 0, 336 | 2 337 | ], 338 | [ 339 | 0, 340 | 2, 341 | 1, 342 | 1, 343 | 0, 344 | 0, 345 | 1, 346 | 0, 347 | 2, 348 | 0, 349 | 0, 350 | 2 351 | ], 352 | [ 353 | 2, 354 | 2, 355 | 2, 356 | 2, 357 | 2, 358 | 2, 359 | 2, 360 | 2, 361 | 2, 362 | 2, 363 | 2, 364 | 2 365 | ] 366 | ], 367 | "rule_severities": { 368 | "bus_definition_conflict": "error", 369 | "bus_entry_needed": "error", 370 | "bus_to_bus_conflict": "error", 371 | "bus_to_net_conflict": "error", 372 | "conflicting_netclasses": "error", 373 | "different_unit_footprint": "error", 374 | "different_unit_net": "error", 375 | "duplicate_reference": "error", 376 | "duplicate_sheet_names": "error", 377 | "endpoint_off_grid": "warning", 378 | "extra_units": "error", 379 | "global_label_dangling": "warning", 380 | "hier_label_mismatch": "error", 381 | "label_dangling": "error", 382 | "lib_symbol_issues": "warning", 383 | "missing_bidi_pin": "warning", 384 | "missing_input_pin": "warning", 385 | "missing_power_pin": "error", 386 | "missing_unit": "warning", 387 | "multiple_net_names": "warning", 388 | "net_not_bus_member": "warning", 389 | "no_connect_connected": "warning", 390 | "no_connect_dangling": "warning", 391 | "pin_not_connected": "error", 392 | "pin_not_driven": "error", 393 | "pin_to_pin": "warning", 394 | "power_pin_not_driven": "error", 395 | "similar_labels": "warning", 396 | "simulation_model_issue": "ignore", 397 | "unannotated": "error", 398 | "unit_value_mismatch": "error", 399 | "unresolved_variable": "error", 400 | "wire_dangling": "error" 401 | } 402 | }, 403 | "libraries": { 404 | "pinned_footprint_libs": [], 405 | "pinned_symbol_libs": [] 406 | }, 407 | "meta": { 408 | "filename": "wii_hdmi_pcb.kicad_pro", 409 | "version": 1 410 | }, 411 | "net_settings": { 412 | "classes": [ 413 | { 414 | "bus_width": 12, 415 | "clearance": 0.2, 416 | "diff_pair_gap": 0.25, 417 | "diff_pair_via_gap": 0.25, 418 | "diff_pair_width": 0.2, 419 | "line_style": 0, 420 | "microvia_diameter": 0.3, 421 | "microvia_drill": 0.1, 422 | "name": "Default", 423 | "pcb_color": "rgba(0, 0, 0, 0.000)", 424 | "schematic_color": "rgba(0, 0, 0, 0.000)", 425 | "track_width": 0.25, 426 | "via_diameter": 0.8, 427 | "via_drill": 0.4, 428 | "wire_width": 6 429 | }, 430 | { 431 | "bus_width": 12, 432 | "clearance": 0.2, 433 | "diff_pair_gap": 0.25, 434 | "diff_pair_via_gap": 0.25, 435 | "diff_pair_width": 0.2, 436 | "line_style": 0, 437 | "microvia_diameter": 0.3, 438 | "microvia_drill": 0.1, 439 | "name": "Small", 440 | "pcb_color": "rgba(0, 0, 0, 0.000)", 441 | "schematic_color": "rgba(0, 0, 0, 0.000)", 442 | "track_width": 0.15, 443 | "via_diameter": 0.6, 444 | "via_drill": 0.3, 445 | "wire_width": 6 446 | } 447 | ], 448 | "meta": { 449 | "version": 3 450 | }, 451 | "net_colors": null, 452 | "netclass_assignments": null, 453 | "netclass_patterns": [ 454 | { 455 | "netclass": "Default", 456 | "pattern": "+5V" 457 | }, 458 | { 459 | "netclass": "Default", 460 | "pattern": "GND" 461 | }, 462 | { 463 | "netclass": "Small", 464 | "pattern": "Net-(J2-Pad14)" 465 | }, 466 | { 467 | "netclass": "Small", 468 | "pattern": "Net-(J2-Pad17)" 469 | }, 470 | { 471 | "netclass": "Small", 472 | "pattern": "Net-(J2-Pad19)" 473 | }, 474 | { 475 | "netclass": "Small", 476 | "pattern": "Net-(J3-Pad1)" 477 | }, 478 | { 479 | "netclass": "Small", 480 | "pattern": "Net-(J3-Pad2)" 481 | }, 482 | { 483 | "netclass": "Small", 484 | "pattern": "Net-(J3-Pad3)" 485 | }, 486 | { 487 | "netclass": "Small", 488 | "pattern": "Net-(J3-Pad4)" 489 | }, 490 | { 491 | "netclass": "Small", 492 | "pattern": "Net-(J3-Pad5)" 493 | }, 494 | { 495 | "netclass": "Small", 496 | "pattern": "Net-(J3-Pad6)" 497 | }, 498 | { 499 | "netclass": "Small", 500 | "pattern": "Net-(U3-Pad5)" 501 | }, 502 | { 503 | "netclass": "Small", 504 | "pattern": "Net-(U3-Pad6)" 505 | }, 506 | { 507 | "netclass": "Small", 508 | "pattern": "POWER_EDID" 509 | }, 510 | { 511 | "netclass": "Small", 512 | "pattern": "SCL" 513 | }, 514 | { 515 | "netclass": "Small", 516 | "pattern": "SDA" 517 | }, 518 | { 519 | "netclass": "Small", 520 | "pattern": "TMDS_CLOCK_+" 521 | }, 522 | { 523 | "netclass": "Small", 524 | "pattern": "TMDS_CLOCK_-" 525 | }, 526 | { 527 | "netclass": "Small", 528 | "pattern": "TMDS_DATA0_+" 529 | }, 530 | { 531 | "netclass": "Small", 532 | "pattern": "TMDS_DATA0_-" 533 | }, 534 | { 535 | "netclass": "Small", 536 | "pattern": "TMDS_DATA1_+" 537 | }, 538 | { 539 | "netclass": "Small", 540 | "pattern": "TMDS_DATA1_-" 541 | }, 542 | { 543 | "netclass": "Small", 544 | "pattern": "TMDS_DATA2_+" 545 | }, 546 | { 547 | "netclass": "Small", 548 | "pattern": "TMDS_DATA2_-" 549 | } 550 | ] 551 | }, 552 | "pcbnew": { 553 | "last_paths": { 554 | "gencad": "", 555 | "idf": "", 556 | "netlist": "", 557 | "specctra_dsn": "", 558 | "step": "", 559 | "vrml": "" 560 | }, 561 | "page_layout_descr_file": "" 562 | }, 563 | "schematic": { 564 | "annotate_start_num": 0, 565 | "drawing": { 566 | "dashed_lines_dash_length_ratio": 12.0, 567 | "dashed_lines_gap_length_ratio": 3.0, 568 | "default_line_thickness": 6.0, 569 | "default_text_size": 50.0, 570 | "field_names": [], 571 | "intersheets_ref_own_page": false, 572 | "intersheets_ref_prefix": "", 573 | "intersheets_ref_short": false, 574 | "intersheets_ref_show": false, 575 | "intersheets_ref_suffix": "", 576 | "junction_size_choice": 3, 577 | "label_size_ratio": 0.25, 578 | "pin_symbol_size": 0.0, 579 | "text_offset_ratio": 0.08 580 | }, 581 | "legacy_lib_dir": "", 582 | "legacy_lib_list": [], 583 | "meta": { 584 | "version": 1 585 | }, 586 | "net_format_name": "", 587 | "page_layout_descr_file": "", 588 | "plot_directory": "", 589 | "spice_current_sheet_as_root": false, 590 | "spice_external_command": "spice \"%I\"", 591 | "spice_model_current_sheet_as_root": true, 592 | "spice_save_all_currents": false, 593 | "spice_save_all_voltages": false, 594 | "subpart_first_id": 65, 595 | "subpart_id_separator": 0 596 | }, 597 | "sheets": [ 598 | [ 599 | "853ee0a4-fdb7-4683-bd25-fbacdf17ab4c", 600 | "" 601 | ] 602 | ], 603 | "text_variables": {} 604 | } 605 | -------------------------------------------------------------------------------- /hardware/wii_flex/LICENSE: -------------------------------------------------------------------------------- 1 | Attribution-NonCommercial-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International 58 | Public License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-NonCommercial-ShareAlike 4.0 International Public License 63 | ("Public License"). To the extent this Public License may be 64 | interpreted as a contract, You are granted the Licensed Rights in 65 | consideration of Your acceptance of these terms and conditions, and the 66 | Licensor grants You such rights in consideration of benefits the 67 | Licensor receives from making the Licensed Material available under 68 | these terms and conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Adapter's License means the license You apply to Your Copyright 84 | and Similar Rights in Your contributions to Adapted Material in 85 | accordance with the terms and conditions of this Public License. 86 | 87 | c. BY-NC-SA Compatible License means a license listed at 88 | creativecommons.org/compatiblelicenses, approved by Creative 89 | Commons as essentially the equivalent of this Public License. 90 | 91 | d. Copyright and Similar Rights means copyright and/or similar rights 92 | closely related to copyright including, without limitation, 93 | performance, broadcast, sound recording, and Sui Generis Database 94 | Rights, without regard to how the rights are labeled or 95 | categorized. For purposes of this Public License, the rights 96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 97 | Rights. 98 | 99 | e. Effective Technological Measures means those measures that, in the 100 | absence of proper authority, may not be circumvented under laws 101 | fulfilling obligations under Article 11 of the WIPO Copyright 102 | Treaty adopted on December 20, 1996, and/or similar international 103 | agreements. 104 | 105 | f. Exceptions and Limitations means fair use, fair dealing, and/or 106 | any other exception or limitation to Copyright and Similar Rights 107 | that applies to Your use of the Licensed Material. 108 | 109 | g. License Elements means the license attributes listed in the name 110 | of a Creative Commons Public License. The License Elements of this 111 | Public License are Attribution, NonCommercial, and ShareAlike. 112 | 113 | h. Licensed Material means the artistic or literary work, database, 114 | or other material to which the Licensor applied this Public 115 | License. 116 | 117 | i. Licensed Rights means the rights granted to You subject to the 118 | terms and conditions of this Public License, which are limited to 119 | all Copyright and Similar Rights that apply to Your use of the 120 | Licensed Material and that the Licensor has authority to license. 121 | 122 | j. Licensor means the individual(s) or entity(ies) granting rights 123 | under this Public License. 124 | 125 | k. NonCommercial means not primarily intended for or directed towards 126 | commercial advantage or monetary compensation. For purposes of 127 | this Public License, the exchange of the Licensed Material for 128 | other material subject to Copyright and Similar Rights by digital 129 | file-sharing or similar means is NonCommercial provided there is 130 | no payment of monetary compensation in connection with the 131 | exchange. 132 | 133 | l. Share means to provide material to the public by any means or 134 | process that requires permission under the Licensed Rights, such 135 | as reproduction, public display, public performance, distribution, 136 | dissemination, communication, or importation, and to make material 137 | available to the public including in ways that members of the 138 | public may access the material from a place and at a time 139 | individually chosen by them. 140 | 141 | m. Sui Generis Database Rights means rights other than copyright 142 | resulting from Directive 96/9/EC of the European Parliament and of 143 | the Council of 11 March 1996 on the legal protection of databases, 144 | as amended and/or succeeded, as well as other essentially 145 | equivalent rights anywhere in the world. 146 | 147 | n. You means the individual or entity exercising the Licensed Rights 148 | under this Public License. Your has a corresponding meaning. 149 | 150 | 151 | Section 2 -- Scope. 152 | 153 | a. License grant. 154 | 155 | 1. Subject to the terms and conditions of this Public License, 156 | the Licensor hereby grants You a worldwide, royalty-free, 157 | non-sublicensable, non-exclusive, irrevocable license to 158 | exercise the Licensed Rights in the Licensed Material to: 159 | 160 | a. reproduce and Share the Licensed Material, in whole or 161 | in part, for NonCommercial purposes only; and 162 | 163 | b. produce, reproduce, and Share Adapted Material for 164 | NonCommercial purposes only. 165 | 166 | 2. Exceptions and Limitations. For the avoidance of doubt, where 167 | Exceptions and Limitations apply to Your use, this Public 168 | License does not apply, and You do not need to comply with 169 | its terms and conditions. 170 | 171 | 3. Term. The term of this Public License is specified in Section 172 | 6(a). 173 | 174 | 4. Media and formats; technical modifications allowed. The 175 | Licensor authorizes You to exercise the Licensed Rights in 176 | all media and formats whether now known or hereafter created, 177 | and to make technical modifications necessary to do so. The 178 | Licensor waives and/or agrees not to assert any right or 179 | authority to forbid You from making technical modifications 180 | necessary to exercise the Licensed Rights, including 181 | technical modifications necessary to circumvent Effective 182 | Technological Measures. For purposes of this Public License, 183 | simply making modifications authorized by this Section 2(a) 184 | (4) never produces Adapted Material. 185 | 186 | 5. Downstream recipients. 187 | 188 | a. Offer from the Licensor -- Licensed Material. Every 189 | recipient of the Licensed Material automatically 190 | receives an offer from the Licensor to exercise the 191 | Licensed Rights under the terms and conditions of this 192 | Public License. 193 | 194 | b. Additional offer from the Licensor -- Adapted Material. 195 | Every recipient of Adapted Material from You 196 | automatically receives an offer from the Licensor to 197 | exercise the Licensed Rights in the Adapted Material 198 | under the conditions of the Adapter's License You apply. 199 | 200 | c. No downstream restrictions. You may not offer or impose 201 | any additional or different terms or conditions on, or 202 | apply any Effective Technological Measures to, the 203 | Licensed Material if doing so restricts exercise of the 204 | Licensed Rights by any recipient of the Licensed 205 | Material. 206 | 207 | 6. No endorsement. Nothing in this Public License constitutes or 208 | may be construed as permission to assert or imply that You 209 | are, or that Your use of the Licensed Material is, connected 210 | with, or sponsored, endorsed, or granted official status by, 211 | the Licensor or others designated to receive attribution as 212 | provided in Section 3(a)(1)(A)(i). 213 | 214 | b. Other rights. 215 | 216 | 1. Moral rights, such as the right of integrity, are not 217 | licensed under this Public License, nor are publicity, 218 | privacy, and/or other similar personality rights; however, to 219 | the extent possible, the Licensor waives and/or agrees not to 220 | assert any such rights held by the Licensor to the limited 221 | extent necessary to allow You to exercise the Licensed 222 | Rights, but not otherwise. 223 | 224 | 2. Patent and trademark rights are not licensed under this 225 | Public License. 226 | 227 | 3. To the extent possible, the Licensor waives any right to 228 | collect royalties from You for the exercise of the Licensed 229 | Rights, whether directly or through a collecting society 230 | under any voluntary or waivable statutory or compulsory 231 | licensing scheme. In all other cases the Licensor expressly 232 | reserves any right to collect such royalties, including when 233 | the Licensed Material is used other than for NonCommercial 234 | purposes. 235 | 236 | 237 | Section 3 -- License Conditions. 238 | 239 | Your exercise of the Licensed Rights is expressly made subject to the 240 | following conditions. 241 | 242 | a. Attribution. 243 | 244 | 1. If You Share the Licensed Material (including in modified 245 | form), You must: 246 | 247 | a. retain the following if it is supplied by the Licensor 248 | with the Licensed Material: 249 | 250 | i. identification of the creator(s) of the Licensed 251 | Material and any others designated to receive 252 | attribution, in any reasonable manner requested by 253 | the Licensor (including by pseudonym if 254 | designated); 255 | 256 | ii. a copyright notice; 257 | 258 | iii. a notice that refers to this Public License; 259 | 260 | iv. a notice that refers to the disclaimer of 261 | warranties; 262 | 263 | v. a URI or hyperlink to the Licensed Material to the 264 | extent reasonably practicable; 265 | 266 | b. indicate if You modified the Licensed Material and 267 | retain an indication of any previous modifications; and 268 | 269 | c. indicate the Licensed Material is licensed under this 270 | Public License, and include the text of, or the URI or 271 | hyperlink to, this Public License. 272 | 273 | 2. You may satisfy the conditions in Section 3(a)(1) in any 274 | reasonable manner based on the medium, means, and context in 275 | which You Share the Licensed Material. For example, it may be 276 | reasonable to satisfy the conditions by providing a URI or 277 | hyperlink to a resource that includes the required 278 | information. 279 | 3. If requested by the Licensor, You must remove any of the 280 | information required by Section 3(a)(1)(A) to the extent 281 | reasonably practicable. 282 | 283 | b. ShareAlike. 284 | 285 | In addition to the conditions in Section 3(a), if You Share 286 | Adapted Material You produce, the following conditions also apply. 287 | 288 | 1. The Adapter's License You apply must be a Creative Commons 289 | license with the same License Elements, this version or 290 | later, or a BY-NC-SA Compatible License. 291 | 292 | 2. You must include the text of, or the URI or hyperlink to, the 293 | Adapter's License You apply. You may satisfy this condition 294 | in any reasonable manner based on the medium, means, and 295 | context in which You Share Adapted Material. 296 | 297 | 3. You may not offer or impose any additional or different terms 298 | or conditions on, or apply any Effective Technological 299 | Measures to, Adapted Material that restrict exercise of the 300 | rights granted under the Adapter's License You apply. 301 | 302 | 303 | Section 4 -- Sui Generis Database Rights. 304 | 305 | Where the Licensed Rights include Sui Generis Database Rights that 306 | apply to Your use of the Licensed Material: 307 | 308 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 309 | to extract, reuse, reproduce, and Share all or a substantial 310 | portion of the contents of the database for NonCommercial purposes 311 | only; 312 | 313 | b. if You include all or a substantial portion of the database 314 | contents in a database in which You have Sui Generis Database 315 | Rights, then the database in which You have Sui Generis Database 316 | Rights (but not its individual contents) is Adapted Material, 317 | including for purposes of Section 3(b); and 318 | 319 | c. You must comply with the conditions in Section 3(a) if You Share 320 | all or a substantial portion of the contents of the database. 321 | 322 | For the avoidance of doubt, this Section 4 supplements and does not 323 | replace Your obligations under this Public License where the Licensed 324 | Rights include other Copyright and Similar Rights. 325 | 326 | 327 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 328 | 329 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 330 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 331 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 332 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 333 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 334 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 335 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 336 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 337 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 338 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 339 | 340 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 341 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 342 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 343 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 344 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 345 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 346 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 347 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 348 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 349 | 350 | c. The disclaimer of warranties and limitation of liability provided 351 | above shall be interpreted in a manner that, to the extent 352 | possible, most closely approximates an absolute disclaimer and 353 | waiver of all liability. 354 | 355 | 356 | Section 6 -- Term and Termination. 357 | 358 | a. This Public License applies for the term of the Copyright and 359 | Similar Rights licensed here. However, if You fail to comply with 360 | this Public License, then Your rights under this Public License 361 | terminate automatically. 362 | 363 | b. Where Your right to use the Licensed Material has terminated under 364 | Section 6(a), it reinstates: 365 | 366 | 1. automatically as of the date the violation is cured, provided 367 | it is cured within 30 days of Your discovery of the 368 | violation; or 369 | 370 | 2. upon express reinstatement by the Licensor. 371 | 372 | For the avoidance of doubt, this Section 6(b) does not affect any 373 | right the Licensor may have to seek remedies for Your violations 374 | of this Public License. 375 | 376 | c. For the avoidance of doubt, the Licensor may also offer the 377 | Licensed Material under separate terms or conditions or stop 378 | distributing the Licensed Material at any time; however, doing so 379 | will not terminate this Public License. 380 | 381 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 382 | License. 383 | 384 | 385 | Section 7 -- Other Terms and Conditions. 386 | 387 | a. The Licensor shall not be bound by any additional or different 388 | terms or conditions communicated by You unless expressly agreed. 389 | 390 | b. Any arrangements, understandings, or agreements regarding the 391 | Licensed Material not stated herein are separate from and 392 | independent of the terms and conditions of this Public License. 393 | 394 | 395 | Section 8 -- Interpretation. 396 | 397 | a. For the avoidance of doubt, this Public License does not, and 398 | shall not be interpreted to, reduce, limit, restrict, or impose 399 | conditions on any use of the Licensed Material that could lawfully 400 | be made without permission under this Public License. 401 | 402 | b. To the extent possible, if any provision of this Public License is 403 | deemed unenforceable, it shall be automatically reformed to the 404 | minimum extent necessary to make it enforceable. If the provision 405 | cannot be reformed, it shall be severed from this Public License 406 | without affecting the enforceability of the remaining terms and 407 | conditions. 408 | 409 | c. No term or condition of this Public License will be waived and no 410 | failure to comply consented to unless expressly agreed to by the 411 | Licensor. 412 | 413 | d. Nothing in this Public License constitutes or may be interpreted 414 | as a limitation upon, or waiver of, any privileges and immunities 415 | that apply to the Licensor or You, including from the legal 416 | processes of any jurisdiction or authority. 417 | 418 | ======================================================================= 419 | 420 | Creative Commons is not a party to its public 421 | licenses. Notwithstanding, Creative Commons may elect to apply one of 422 | its public licenses to material it publishes and in those instances 423 | will be considered the “Licensor.” The text of the Creative Commons 424 | public licenses is dedicated to the public domain under the CC0 Public 425 | Domain Dedication. Except for the limited purpose of indicating that 426 | material is shared under a Creative Commons public license or as 427 | otherwise permitted by the Creative Commons policies published at 428 | creativecommons.org/policies, Creative Commons does not authorize the 429 | use of the trademark "Creative Commons" or any other trademark or logo 430 | of Creative Commons without its prior written consent including, 431 | without limitation, in connection with any unauthorized modifications 432 | to any of its public licenses or any other arrangements, 433 | understandings, or agreements concerning use of licensed material. For 434 | the avoidance of doubt, this paragraph does not form part of the 435 | public licenses. 436 | 437 | Creative Commons may be contacted at creativecommons.org. 438 | 439 | --------------------------------------------------------------------------------