├── psvr2-pc
├── psvr2-pc.pdf
├── psvr2-pc.png
├── simulation
│ ├── simulation.kicad_pcb
│ ├── _spice_component_models
│ │ ├── README.txt
│ │ ├── AO3401A.mod
│ │ └── MMBT2222A.txt
│ ├── simulation.kicad_prl
│ └── simulation.kicad_pro
├── fp-lib-table
├── sym-lib-table
├── psvr2-pc.round-tracks-config
├── psvr2-pc.kicad_prl
├── Twemoji_1f427_soldermask.svg
├── IEC60417-5926_Polarity_of_DC_power_connector.svg
├── Twemoji_1f427.svg
├── JLC2KiCad_lib.pretty
│ ├── SW-SMD_4P-L5.1-W5.1-P3.70-LS6.5-TL-2.kicad_mod
│ ├── USB-C-SMD_TYPE-C-USB-18.kicad_mod
│ ├── CONN-SMD_472720001.kicad_mod
│ └── USB-SMD_692622030100.kicad_mod
└── psvr2-pc.kicad_pro
├── enclosure
└── enclosure.blend
├── firmware
├── build
│ └── padaptwor.uf2
├── capture-request-pdo-steam-deck-charger.bin
├── capture-request-pdo-hackaday-altmodefriend-example.bin
├── capture-source-capabilities-pdo-steam-deck-charger.bin
├── capture-source-capabilities-pdo-hackaday-altmodefriend-example.bin
├── .vscode
│ ├── settings.json
│ └── launch.json
├── CMakeLists.txt
├── boards
│ └── psdaptwor.h
├── pico_sdk_import.cmake
├── swy-type-c-pd-messages.bt
├── fusb302_defines.h
└── main.c
├── .gitattributes
├── README.md
└── LICENSE
/psvr2-pc/psvr2-pc.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Swyter/psdaptwor/HEAD/psvr2-pc/psvr2-pc.pdf
--------------------------------------------------------------------------------
/psvr2-pc/psvr2-pc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Swyter/psdaptwor/HEAD/psvr2-pc/psvr2-pc.png
--------------------------------------------------------------------------------
/enclosure/enclosure.blend:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Swyter/psdaptwor/HEAD/enclosure/enclosure.blend
--------------------------------------------------------------------------------
/firmware/build/padaptwor.uf2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Swyter/psdaptwor/HEAD/firmware/build/padaptwor.uf2
--------------------------------------------------------------------------------
/psvr2-pc/simulation/simulation.kicad_pcb:
--------------------------------------------------------------------------------
1 | (kicad_pcb (version 20240108) (generator "pcbnew") (generator_version "8.0")
2 | )
--------------------------------------------------------------------------------
/firmware/capture-request-pdo-steam-deck-charger.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Swyter/psdaptwor/HEAD/firmware/capture-request-pdo-steam-deck-charger.bin
--------------------------------------------------------------------------------
/firmware/capture-request-pdo-hackaday-altmodefriend-example.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Swyter/psdaptwor/HEAD/firmware/capture-request-pdo-hackaday-altmodefriend-example.bin
--------------------------------------------------------------------------------
/firmware/capture-source-capabilities-pdo-steam-deck-charger.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Swyter/psdaptwor/HEAD/firmware/capture-source-capabilities-pdo-steam-deck-charger.bin
--------------------------------------------------------------------------------
/psvr2-pc/fp-lib-table:
--------------------------------------------------------------------------------
1 | (fp_lib_table
2 | (version 7)
3 | (lib (name "JLC2KiCad_lib")(type "KiCad")(uri "${KIPRJMOD}/JLC2KiCad_lib.pretty")(options "")(descr ""))
4 | )
5 |
--------------------------------------------------------------------------------
/firmware/capture-source-capabilities-pdo-hackaday-altmodefriend-example.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Swyter/psdaptwor/HEAD/firmware/capture-source-capabilities-pdo-hackaday-altmodefriend-example.bin
--------------------------------------------------------------------------------
/psvr2-pc/sym-lib-table:
--------------------------------------------------------------------------------
1 | (sym_lib_table
2 | (version 7)
3 | (lib (name "47272-0001")(type "KiCad")(uri "C:/Users/Usuario/Documents/KiCad/7.0/symbols/47272-0001.kicad_sym")(options "")(descr ""))
4 | )
5 |
--------------------------------------------------------------------------------
/psvr2-pc/psvr2-pc.round-tracks-config:
--------------------------------------------------------------------------------
1 | Default True 3.0 3
2 | High speed differential DP (100 Ω ±10% impedance) True 2.0 3
3 | High speed differential SS (90 Ω ±7Ω impedance) True 2.0 3
4 | Power True 2.0 3
5 | False True True
6 |
--------------------------------------------------------------------------------
/psvr2-pc/simulation/_spice_component_models/README.txt:
--------------------------------------------------------------------------------
1 | https://www.nexperia.com/products/bipolar-transistors/general-purpose-and-low-vcesat-bipolar-transistors/single-bipolar-transistors/single-bipolar-transistors-100-v/MMBT2222A.html
2 | https://assets.nexperia.com/documents/spice-model/MMBT2222A.txt
3 |
4 |
5 | https://github.com/rdmeneze/LTSpiceModels/blob/master/AO3401A.mod
6 |
--------------------------------------------------------------------------------
/firmware/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "cmake.generator": "Ninja",
3 | "cmake.options.statusBarVisibility": "visible",
4 | "cmake.environment": {
5 | "PICO_SDK_PATH": "C:/Program Files/Raspberry Pi/Pico SDK v1.5.1/pico-sdk", /* swy: change your folder here; they should have added an environmental variable themselves :( */
6 | "PICO_TOOLCHAIN_PATH": "${env:PICO_SDK_PATH}/../gcc-arm-none-eabi",
7 | "CMAKE_MAKE_PROGRAM": "${env:PICO_SDK_PATH}/../ninja/ninja"
8 | },
9 | "files.associations": {
10 | "fusb302_defines.h": "c"
11 | }
12 | }
--------------------------------------------------------------------------------
/psvr2-pc/simulation/_spice_component_models/AO3401A.mod:
--------------------------------------------------------------------------------
1 | .SUBCKT AO3401A 4 1 2
2 | M1 3 1 2 2 PMOS W=998956u L=1.0u
3 | M2 2 1 2 4 NMOS W=998956u L=0.7u
4 | R1 4 3 RTEMP 17E-3
5 | CGS 1 2 30E-12
6 | DBD 3 2 DBD
7 | **************************************************************************
8 | .MODEL PMOS PMOS (LEVEL = 3 TOX = 2.5E-8
9 | + RS = 2E-4 RD = 0 NSUB = 2E17
10 | + UO = 120 THETA = 0.2 VTO=-1.1
11 | + VMAX = 5e6 XJ = 4E-7 KAPPA = 1.2
12 | + ETA = 0 TPG = 1
13 | + IS = 0 LD = 0
14 | + CGSO = 0 CGDO = 0 CGBO = 0
15 | + NFS = 2E10 DELTA = 0)
16 | *************************************************************************
17 | .MODEL NMOS NMOS (LEVEL = 3 TOX = 5.2E-8
18 | +NSUB = 2.0E16 TPG = -1)
19 | *************************************************************************
20 | .MODEL DBD D (CJO=900E-13 VJ=0.6 M=0.3
21 | +RS=0.005 FC=0.5 IS=1E-12 TT=1.6E-8 N=1.0 BV=36 IBV=1E-4)
22 | *************************************************************************
23 | .MODEL RTEMP RES (TC1=1.5E-3 TC2=1E-6)
24 | *************************************************************************
25 | .ENDS
26 |
--------------------------------------------------------------------------------
/psvr2-pc/psvr2-pc.kicad_prl:
--------------------------------------------------------------------------------
1 | {
2 | "board": {
3 | "active_layer": 2,
4 | "active_layer_preset": "",
5 | "auto_track_width": true,
6 | "hidden_netclasses": [],
7 | "hidden_nets": [],
8 | "high_contrast_mode": 1,
9 | "net_color_mode": 1,
10 | "opacity": {
11 | "images": 0.5799999833106995,
12 | "pads": 1.0,
13 | "tracks": 1.0,
14 | "vias": 1.0,
15 | "zones": 0.6
16 | },
17 | "selection_filter": {
18 | "dimensions": true,
19 | "footprints": true,
20 | "graphics": true,
21 | "keepouts": true,
22 | "lockedItems": true,
23 | "otherItems": true,
24 | "pads": true,
25 | "text": true,
26 | "tracks": true,
27 | "vias": true,
28 | "zones": true
29 | },
30 | "visible_items": [
31 | 0,
32 | 1,
33 | 2,
34 | 3,
35 | 4,
36 | 5,
37 | 8,
38 | 9,
39 | 10,
40 | 11,
41 | 13,
42 | 15,
43 | 16,
44 | 17,
45 | 18,
46 | 19,
47 | 20,
48 | 21,
49 | 22,
50 | 23,
51 | 24,
52 | 25,
53 | 26,
54 | 27,
55 | 28,
56 | 29,
57 | 30,
58 | 32,
59 | 33,
60 | 34,
61 | 35,
62 | 36,
63 | 39,
64 | 40
65 | ],
66 | "visible_layers": "ffdfff0_ffffffff",
67 | "zone_display_mode": 0
68 | },
69 | "meta": {
70 | "filename": "psvr2-pc.kicad_prl",
71 | "version": 3
72 | },
73 | "project": {
74 | "files": []
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/psvr2-pc/Twemoji_1f427_soldermask.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/firmware/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.12)
2 |
3 | #set(PICO_SDK_PATH "C:/Program Files/Raspberry Pi/Pico SDK v1.5.1/pico-sdk")
4 | #set(PICO_TOOLCHAIN_PATH "${PICO_SDK_PATH}/../gcc-arm-none-eabi")
5 | #set(CMAKE_MAKE_PROGRAM "${PICO_SDK_PATH}/../ninja/ninja")
6 |
7 | # Pull in SDK (must be before project)
8 | include(pico_sdk_import.cmake)
9 |
10 | project(psdaptwor C CXX ASM)
11 | set(CMAKE_C_STANDARD 11)
12 | set(CMAKE_CXX_STANDARD 17)
13 |
14 | # swy: write a RAM-only .uf2 file that does not persist, can be run with `picotool load -x psdaptwor.uf2`
15 | set(PICO_NO_FLASH 1)
16 |
17 | set(PICO_BOARD psdaptwor)
18 | set(PICO_BOARD_HEADER_DIRS "${PROJECT_SOURCE_DIR}/boards")
19 |
20 | if (PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0")
21 | message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
22 | endif()
23 |
24 | # Initialize the SDK
25 | pico_sdk_init()
26 |
27 | # Add blink example
28 | add_executable(padaptwor main.c)
29 |
30 | # pull in common dependencies
31 | target_link_libraries(padaptwor pico_stdlib hardware_adc hardware_i2c)
32 |
33 | pico_enable_stdio_usb(padaptwor ENABLED)
34 |
35 | # create map/bin/hex file etc.
36 | pico_add_extra_outputs(padaptwor)
37 |
38 |
39 | add_compile_options(-Wall
40 | -Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int
41 | -Wno-unused-function # we have some for the docs that aren't called
42 | )
43 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
44 | add_compile_options(-Wno-maybe-uninitialized)
45 | endif()
46 |
--------------------------------------------------------------------------------
/psvr2-pc/IEC60417-5926_Polarity_of_DC_power_connector.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/psvr2-pc/simulation/simulation.kicad_prl:
--------------------------------------------------------------------------------
1 | {
2 | "board": {
3 | "active_layer": 0,
4 | "active_layer_preset": "",
5 | "auto_track_width": true,
6 | "hidden_netclasses": [],
7 | "hidden_nets": [],
8 | "high_contrast_mode": 0,
9 | "net_color_mode": 1,
10 | "opacity": {
11 | "images": 0.6,
12 | "pads": 1.0,
13 | "tracks": 1.0,
14 | "vias": 1.0,
15 | "zones": 0.6
16 | },
17 | "selection_filter": {
18 | "dimensions": true,
19 | "footprints": true,
20 | "graphics": true,
21 | "keepouts": true,
22 | "lockedItems": false,
23 | "otherItems": true,
24 | "pads": true,
25 | "text": true,
26 | "tracks": true,
27 | "vias": true,
28 | "zones": true
29 | },
30 | "visible_items": [
31 | 0,
32 | 1,
33 | 2,
34 | 3,
35 | 4,
36 | 5,
37 | 8,
38 | 9,
39 | 10,
40 | 11,
41 | 12,
42 | 13,
43 | 15,
44 | 16,
45 | 17,
46 | 18,
47 | 19,
48 | 20,
49 | 21,
50 | 22,
51 | 23,
52 | 24,
53 | 25,
54 | 26,
55 | 27,
56 | 28,
57 | 29,
58 | 30,
59 | 32,
60 | 33,
61 | 34,
62 | 35,
63 | 36,
64 | 39,
65 | 40
66 | ],
67 | "visible_layers": "fffffff_ffffffff",
68 | "zone_display_mode": 0
69 | },
70 | "git": {
71 | "repo_password": "",
72 | "repo_type": "",
73 | "repo_username": "",
74 | "ssh_key": ""
75 | },
76 | "meta": {
77 | "filename": "simulation.kicad_prl",
78 | "version": 3
79 | },
80 | "project": {
81 | "files": []
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/psvr2-pc/simulation/_spice_component_models/MMBT2222A.txt:
--------------------------------------------------------------------------------
1 | ***********************************************************
2 | *
3 | * MMBT2222A
4 | *
5 | * Nexperia
6 | *
7 | * Switching NPN Transistor
8 | * IC = 600 mA
9 | * VCEO = 40 V
10 | * hFE = min. 40 @ 10V/500mA
11 | *
12 | *
13 | *
14 | *
15 | * Package pinning does not match Spice model pinning.
16 | * Package: SOT 23
17 | *
18 | * Package Pin 1: Base
19 | * Package Pin 2: Emitter
20 | * Package Pin 3: Collector
21 | *
22 | *
23 | * Extraction date (week/year): 08/2022
24 | * Spicemodel includes temperature dependency
25 | *
26 | **********************************************************
27 | *#
28 | * Please note: Diode D1, Transistor Q2 and Resistor RQ
29 | * are dedicated to improve modeling of quasi
30 | * saturation area and reverse mode operation
31 | * and do not reflect physical devices.
32 | *
33 | .SUBCKT MMBT2222A 1 2 3
34 | Q1 1 2 3 MAIN 0.8689
35 | RQ 1 11 38.53
36 | Q2 11 2 3 MAIN 0.1311
37 | D1 2 1 DIODE
38 | *
39 | .MODEL MAIN NPN
40 | + IS = 1.739E-14
41 | + NF = 0.9609
42 | + ISE = 7.98E-15
43 | + NE = 1.339
44 | + BF = 260
45 | + IKF = 0.1527
46 | + VAF = 10.21
47 | + NR = 0.9577
48 | + ISC = 2.882E-15
49 | + NC = 1.268
50 | + BR = 5.7
51 | + IKR = 1.527
52 | + VAR = 25
53 | + RB = 58
54 | + IRB = 0.0003
55 | + RBM = 2.5
56 | + RE = 0.2044
57 | + RC = 0.3651
58 | + XTB = 0.3793
59 | + EG = 1.11
60 | + XTI = -7.536
61 | + CJE = 2.521E-11
62 | + VJE = 0.6848
63 | + MJE = 0.3217
64 | + TF = 4.303E-10
65 | + XTF = 10.53
66 | + VTF = 2
67 | + ITF = 0.68
68 | + PTF = 0
69 | + CJC = 5.958E-12
70 | + VJC = 0.6251
71 | + MJC = 0.3364
72 | + XCJC = 1
73 | + TR = 7E-08
74 | + CJS = 0
75 | + VJS = 0.75
76 | + MJS = 0.333
77 | + FC = 0.9552
78 | .MODEL DIODE D
79 | + IS = 8.947E-13
80 | + N = 1.113
81 | + BV = 1000
82 | + IBV = 0.001
83 | + RS = 159.3
84 | + CJO = 0
85 | + VJ = 1
86 | + M = 0.5
87 | + FC = 0
88 | + TT = 0
89 | + EG = 1.11
90 | + XTI = 3
91 | .ENDS
92 | *
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # author: GitHub@TitanRGB
2 | # This document allows GitHub to correctly identify Altium Designer, KiCAD, Gerber and Eagle documents and add them to GitHub Repository's language statistics.
3 | # 这个文档可以使GitHub正确的识别Altium Designer、KiCAD、Gerber以及Eagle的文档,并将它们加入到GitHub Repository的语言统计中。
4 |
5 | # https://gist.github.com/TitanRGB/61c37bf71159cc9a511558ec7c218339
6 |
7 | *.OutJob linguist-detectable=true
8 | *.PcbDoc linguist-detectable=true
9 | *.PrjPCB linguist-detectable=true
10 | *.SchDoc linguist-detectable=true
11 | *.outjob linguist-detectable=true
12 | *.pcbdoc linguist-detectable=true
13 | *.prjpcb linguist-detectable=true
14 | *.schdoc linguist-detectable=true
15 | *.PCB linguist-detectable=true
16 | *.sch linguist-detectable=true
17 | *.lib linguist-detectable=true
18 | *.epf linguist-detectable=true
19 | *.brd linguist-detectable=true
20 | *.pro linguist-detectable=true
21 | *.gbr linguist-detectable=true
22 | *.cmp linguist-detectable=true
23 | *.gbl linguist-detectable=true
24 | *.gbo linguist-detectable=true
25 | *.gbp linguist-detectable=true
26 | *.gbs linguist-detectable=true
27 | *.gko linguist-detectable=true
28 | *.gml linguist-detectable=true
29 | *.gpb linguist-detectable=true
30 | *.gpt linguist-detectable=true
31 | *.gtl linguist-detectable=true
32 | *.gto linguist-detectable=true
33 | *.gtp linguist-detectable=true
34 | *.gts linguist-detectable=true
35 | *.ncl linguist-detectable=true
36 | *.sol linguist-detectable=true
37 | *.GBR linguist-detectable=true
38 | *.CMP linguist-detectable=true
39 | *.GBL linguist-detectable=true
40 | *.GBO linguist-detectable=true
41 | *.GBP linguist-detectable=true
42 | *.GBS linguist-detectable=true
43 | *.GKO linguist-detectable=true
44 | *.GML linguist-detectable=true
45 | *.GBP linguist-detectable=true
46 | *.GPT linguist-detectable=true
47 | *.GTL linguist-detectable=true
48 | *.GTO linguist-detectable=true
49 | *.GTP linguist-detectable=true
50 | *.GTS linguist-detectable=true
51 | *.NCL linguist-detectable=true
52 | *.SOL linguist-detectable=true
53 | *.kicad_pcb linguist-detectable=true
54 | *.pro linguist-detectable=true
55 | *.obj linguist-detectable=true
56 | *.stl linguist-detectable=true
57 | *.md linguist-detectable=true
58 | *.dxf linguist-detectable=true
59 | *.dwg linguist-detectable=true
60 |
--------------------------------------------------------------------------------
/psvr2-pc/Twemoji_1f427.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # What is `psdaptwor`?
2 | An experimental PC adapter for EPCOT —the PlayStation®VR2 headset— that splits USB Type-C® into DisplayPort video, USB 3 data and power. Intercepting its DP-AUX/SBU and CC side channels.
3 |
4 | > **Important**: *This is my first electronics project and I am still ironing the whole thing out, I have gotten here with a lot of hints and reviews from people who actually know what they are doing, but it should be considered non-functional, for now.*
5 |
6 | # How do I get one?
7 | Once the project is properly tested and the design is finalized we will provide the manufacturing files to order assembled boards from any affordable printed circuit board (PCB) fabrication house.
8 | The final aim of the project is that one assembled adapter should cost less than 50€; the design and components are being aggresively optimized as much as possible. Getting one or two should be feasible for almost anyone.
9 |
10 | # What does it look like?
11 | More or less like this, the dimensions are around *6.3 x 10.2 centimeters*; much tinier than it looks like here:
12 |
13 | 
14 |
15 | # What is that name? Do you know how to spell?
16 |
17 | No, it is not a typo. I needed something that could be unique and searchable, and contained `PS`, `VR` and `two` somewhere.
18 | Sony products (like the memory card USB one) seem to call their adapters adaptors, so I follow their naming scheme.
19 |
20 | You can call it the *pee ess virtual adaptor*. :)
21 |
22 | # Credits and acknowledgements
23 | * *`@JX35`*: For the *DisplayPort AUX emulator* board this is heavily based on, and uncountable references, ideas and suggestions.
24 | * *`@mrandTX`*: Hardware reviews, many suggestions, things I wouldn't have even thought about and encouragement.
25 | * *`@thaytan`, `@ivry.vr` and many others around the Monado project*: Crucial research and development about how the PS®VR2 hardware and software actually functions. Standing on the shoulders of giants, this just cobbles stuff together. Many thanks.
26 | * *[`jorticus/DPSwitch`](https://github.com/jorticus/DPSwitch)*, for the initial DisplayPort symbols and schematic that I used as a start point to learn the program and a good reference of how to use KiCad buses to group signals.
27 | * *[`diva-eng/diva-card`](https://github.com/diva-eng/diva-card)*, for the known-good 12 MHz 20pF crystal oscillator circuit using cheap JLCPCB basic parts, and the capacitor/resistor values.
28 |
--------------------------------------------------------------------------------
/firmware/boards/psdaptwor.h:
--------------------------------------------------------------------------------
1 | /**
2 | * | psdaptwor - an experimental PSVR2 to PC adaptor | custom RP2040 board pinout and boot-up defines
3 | * | created by Swyter
4 | *
5 | * SPDX-License-Identifier: GPL-2.0-or-later
6 | */
7 |
8 | // -----------------------------------------------------
9 | // NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
10 | // SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
11 | // -----------------------------------------------------
12 |
13 | #ifndef _BOARDS_SWYTER_PSDAPTWOR_RP2040_H
14 | #define _BOARDS_SWYTER_PSDAPTWOR_RP2040_H
15 |
16 | // For board detection
17 | #define SWYTER_PSDAPTWOR_RP2040
18 |
19 | // On some samples, the xosc can take longer to stabilize than is usual
20 | #ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER
21 | #define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64
22 | #endif
23 |
24 | //------------- UART -------------//
25 | #ifndef PICO_DEFAULT_UART
26 | #define PICO_DEFAULT_UART 0 /* swy: we need to use [UART HW BLOCK 0] for GPIO12 and GPIO13, it's the only function that can be used in those pins; [UART HW BLOCK 1] won't work here */
27 | #endif
28 |
29 | #ifndef PICO_DEFAULT_UART_TX_PIN
30 | #define PICO_DEFAULT_UART_TX_PIN 12 /* swy: GPIO12 */
31 | #endif
32 |
33 | #ifndef PICO_DEFAULT_UART_RX_PIN
34 | #define PICO_DEFAULT_UART_RX_PIN 13 /* swy: GPIO13 */
35 | #endif
36 |
37 | //------------- LED -------------//
38 | #ifndef PICO_DEFAULT_LED_PIN
39 | #define PICO_DEFAULT_LED_PIN 14 /* swy: GPIO14, also known as PSDAPT_PIN_LED_CONN_WRONG_ORIENT */
40 | #endif
41 |
42 | //------------- I2C -------------//
43 | #ifndef PICO_DEFAULT_I2C
44 | #define PICO_DEFAULT_I2C 0 /* swy: important: we need to use [I2C HW Block 0], which is the only function that works for GPIO0 and GPIO1. [I2C HW Block 1] won't do anything unless you change pins; see the diagram in gpio.h */
45 | #endif
46 |
47 | #ifndef PICO_DEFAULT_I2C_SDA_PIN
48 | #define PICO_DEFAULT_I2C_SDA_PIN 0 /* swy: GPIO0 */
49 | #endif
50 |
51 | #ifndef PICO_DEFAULT_I2C_SCL_PIN
52 | #define PICO_DEFAULT_I2C_SCL_PIN 1 /* swy: GPIO1 */
53 | #endif
54 |
55 | //------------- FLASH -------------//
56 |
57 | // Use slower generic flash access
58 | #define PICO_BOOT_STAGE2_CHOOSE_GENERIC_03H 1
59 |
60 | #ifndef PICO_FLASH_SPI_CLKDIV
61 | #define PICO_FLASH_SPI_CLKDIV 4
62 | #endif
63 |
64 | #ifndef PICO_FLASH_SIZE_BYTES
65 | #define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) /* swy: 16 MiB for the W25Q128JVSIQ flash chip, or 128 Mbits in manufacturer lingo */
66 | #endif
67 |
68 | // All boards have B1 RP2040
69 | #ifndef PICO_RP2040_B0_SUPPORTED
70 | #define PICO_RP2040_B0_SUPPORTED 0
71 | #endif
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/firmware/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.2.0",
3 | "configurations": [
4 | { "name": "Pico Debug",
5 | "program": "${command:cmake.launchTargetPath}",
6 | // swy: upload pico-debug-gimmecache.uf2 to have in-device debugging using the second RP2040 Arm core,
7 | // no need to wire a second board via SWD pins to use as a relay:
8 | // https://github.com/majbthrd/pico-debug/blob/master/howto/vscode1.md
9 | // https://community.infineon.com/t5/PSoC-4/OpenOCD-debugging-in-visual-studio-code/td-p/290060
10 | //"showDevDebugOutput": "raw",
11 | "device": "RP2040",
12 | "gdbPath": "${config:cmake.environment.PICO_SDK_PATH}/../gcc-arm-none-eabi/bin/arm-none-eabi-gdb",
13 | "cwd": "${workspaceRoot}",
14 | "executable": "${workspaceRoot}/build/padaptwor.elf",
15 | "request": "launch",
16 | "type": "cortex-debug",
17 | "servertype": "openocd",
18 | "serverpath": "${config:cmake.environment.PICO_SDK_PATH}/../openocd/openocd",
19 | "configFiles": [
20 | "interface/cmsis-dap.cfg",
21 | "target/rp2040-core0.cfg"
22 | ],
23 | "openOCDLaunchCommands": [
24 | "transport select swd",
25 | "adapter speed 4000"
26 | ],
27 | "svdFile": "${config:cmake.environment.PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
28 | "runToMain": true,
29 | "postRestartCommands": [
30 | "break main",
31 | "continue"
32 | ],
33 | "searchDir": [
34 | "${config:cmake.environment.PICO_SDK_PATH}/../openocd/scripts"
35 | ],
36 | },
37 | {
38 | "request": "launch",
39 | "name": "picotool load exec (no flash)",
40 | "type": "node-terminal",
41 | "command": "cd \"${config:cmake.environment.PICO_SDK_PATH}/../picotool\"; ./picotool reboot -f -u; sleep 1; ./picotool load -x ${workspaceRoot}/build/padaptwor.elf;"
42 | },
43 | {
44 | "request": "launch",
45 | "name": "picotool load (flash)",
46 | "type": "node-terminal",
47 | "command": "cd \"${config:cmake.environment.PICO_SDK_PATH}/../picotool\"; ./picotool reboot -f -u; sleep 1; ./picotool load ${workspaceRoot}/build/padaptwor.elf;"
48 | },
49 | {
50 | "request": "launch",
51 | "name": "picotool reboot",
52 | "type": "node-terminal",
53 | "command": "cd \"${config:cmake.environment.PICO_SDK_PATH}/../picotool\"; ./picotool reboot -f"
54 | }
55 | ]
56 | }
--------------------------------------------------------------------------------
/psvr2-pc/JLC2KiCad_lib.pretty/SW-SMD_4P-L5.1-W5.1-P3.70-LS6.5-TL-2.kicad_mod:
--------------------------------------------------------------------------------
1 | (module "SW-SMD_4P-L5.1-W5.1-P3.70-LS6.5-TL-2" (layer F.Cu) (tedit 65E534C4)
2 | (descr "SW-SMD_4P-L5.1-W5.1-P3.70-LS6.5-TL-2 footprint")
3 | (tags "SW-SMD_4P-L5.1-W5.1-P3.70-LS6.5-TL-2 footprint C318884")
4 | (attr smd)
5 | (fp_text reference REF** (at 0 -4.550165) (layer F.SilkS)
6 | (effects (font (size 1 1) (thickness 0.15)))
7 | )
8 | (fp_text value SW-SMD_4P-L5.1-W5.1-P3.70-LS6.5-TL-2 (at 0 4.550165) (layer F.Fab)
9 | (effects (font (size 1 1) (thickness 0.15)))
10 | )
11 | (fp_circle (center -3.249936 -2.549911) (end -3.219964 -2.549911) (layer F.SilkS) (width 0.059995))
12 | (fp_circle (center 0 0) (end 1.275083 0) (layer F.SilkS) (width 0.254001))
13 | (fp_line (start -1.000762 -1.800864) (end 0.899162 -1.800864) (layer F.SilkS) (width 0.254001))
14 | (fp_line (start 0.899162 -1.800864) (end 1.800864 -0.899162) (layer F.SilkS) (width 0.254001))
15 | (fp_line (start 1.800864 -0.899162) (end 1.800864 0.899162) (layer F.SilkS) (width 0.254001))
16 | (fp_line (start 1.800864 0.899162) (end 0.800102 1.899924) (layer F.SilkS) (width 0.254001))
17 | (fp_line (start 0.800102 1.899924) (end -0.899162 1.899924) (layer F.SilkS) (width 0.254001))
18 | (fp_line (start -0.899162 1.899924) (end -1.800864 0.998222) (layer F.SilkS) (width 0.254001))
19 | (fp_line (start -1.800864 0.998222) (end -1.800864 -1.000762) (layer F.SilkS) (width 0.254001))
20 | (fp_line (start -1.800864 -1.000762) (end -1.000762 -1.800864) (layer F.SilkS) (width 0.254001))
21 | (fp_line (start 1.275083 -2.550165) (end 2.170155 -1.655093) (layer F.SilkS) (width 0.254001))
22 | (fp_line (start 2.550165 -1.168402) (end 2.550165 1.168402) (layer F.SilkS) (width 0.254001))
23 | (fp_line (start 2.170155 1.655093) (end 1.275083 2.550165) (layer F.SilkS) (width 0.254001))
24 | (fp_line (start -2.550165 -1.168402) (end -2.550165 1.168402) (layer F.SilkS) (width 0.254001))
25 | (fp_line (start -2.170155 1.655093) (end -1.275083 2.550165) (layer F.SilkS) (width 0.254001))
26 | (fp_line (start -1.275083 -2.550165) (end -2.170155 -1.655093) (layer F.SilkS) (width 0.254001))
27 | (fp_line (start -1.275083 2.550165) (end 1.275083 2.550165) (layer F.SilkS) (width 0.254001))
28 | (fp_line (start -1.275083 -2.550165) (end 1.275083 -2.550165) (layer F.SilkS) (width 0.254001))
29 | (pad 1 smd rect (at -3.299975 -1.850191) (size 1.7 1) (layers F.Cu F.Mask F.Paste))
30 | (pad 2 smd rect (at 3.299975 -1.850216) (size 1.7 1) (layers F.Cu F.Mask F.Paste))
31 | (pad 3 smd rect (at -3.299975 1.850216) (size 1.7 1) (layers F.Cu F.Mask F.Paste))
32 | (pad 4 smd rect (at 3.299975 1.850191) (size 1.7 1) (layers F.Cu F.Mask F.Paste))
33 | (fp_text user REF** (at 0 6.550165) (layer F.Fab)
34 | (effects (font (size 1 1) (thickness 0.15)))
35 | )
36 | (model ./JLC2KiCad_lib.pretty/packages3d/SW-SMD_4P-L5.1-W5.1-P3.70-LS6.5-TL-2.step
37 | (at (xyz 0 0 0))
38 | (scale (xyz 1 1 1))
39 | (rotate (xyz 0 0 0))
40 | )
41 | )
--------------------------------------------------------------------------------
/firmware/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 | # GIT_SUBMODULES_RECURSE was added in 3.17
33 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
34 | FetchContent_Declare(
35 | pico_sdk
36 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
37 | GIT_TAG master
38 | GIT_SUBMODULES_RECURSE FALSE
39 | )
40 | else ()
41 | FetchContent_Declare(
42 | pico_sdk
43 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
44 | GIT_TAG master
45 | )
46 | endif ()
47 |
48 | if (NOT pico_sdk)
49 | message("Downloading Raspberry Pi Pico SDK")
50 | FetchContent_Populate(pico_sdk)
51 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
52 | endif ()
53 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
54 | else ()
55 | message(FATAL_ERROR
56 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
57 | )
58 | endif ()
59 | endif ()
60 |
61 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
62 | if (NOT EXISTS ${PICO_SDK_PATH})
63 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
64 | endif ()
65 |
66 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
67 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
68 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
69 | endif ()
70 |
71 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
72 |
73 | include(${PICO_SDK_INIT_CMAKE_FILE})
74 |
--------------------------------------------------------------------------------
/psvr2-pc/JLC2KiCad_lib.pretty/USB-C-SMD_TYPE-C-USB-18.kicad_mod:
--------------------------------------------------------------------------------
1 | (module "USB-C-SMD_TYPE-C-USB-18" (layer F.Cu) (tedit 65E4C98B)
2 | (descr "USB-C-SMD_TYPE-C-USB-18 footprint")
3 | (tags "USB-C-SMD_TYPE-C-USB-18 footprint C134092")
4 | (attr through_hole)
5 | (fp_text reference REF** (at 0 -4.909957) (layer F.SilkS)
6 | (effects (font (size 1 1) (thickness 0.15)))
7 | )
8 | (fp_text value USB-C-SMD_TYPE-C-USB-18 (at 0 6.680036) (layer F.Fab)
9 | (effects (font (size 1 1) (thickness 0.15)))
10 | )
11 | (fp_circle (center -4.480061 -3.025019) (end -4.450089 -3.025019) (layer F.SilkS) (width 0.059995))
12 | (fp_circle (center -3.459995 -3.510008) (end -3.309982 -3.510008) (layer F.Fab) (width 0.3))
13 | (fp_circle (center -3.459995 -3.510008) (end -3.309982 -3.510008) (layer F.SilkS) (width 0.3))
14 | (fp_line (start 4.31999 4.680036) (end -4.31999 4.680036) (layer F.SilkS) (width 0.254001))
15 | (fp_line (start -3.4889 -2.474981) (end -3.376378 -2.474981) (layer F.SilkS) (width 0.254001))
16 | (fp_line (start -0.121514 -2.474981) (end 0.125654 -2.474981) (layer F.SilkS) (width 0.254001))
17 | (fp_line (start 3.378486 -2.474981) (end 3.4889 -2.474981) (layer F.SilkS) (width 0.254001))
18 | (fp_line (start 4.31999 -1.118821) (end 4.31999 1.428829) (layer F.SilkS) (width 0.254001))
19 | (fp_line (start 4.31999 4.391085) (end 4.31999 4.680036) (layer F.SilkS) (width 0.254001))
20 | (fp_line (start -4.31999 4.680036) (end -4.31999 4.391085) (layer F.SilkS) (width 0.254001))
21 | (fp_line (start -4.31999 1.428829) (end -4.31999 -1.118821) (layer F.SilkS) (width 0.254001))
22 | (pad A1 smd rect (at -3 -2.909957) (size 0.3 0.8) (layers F.Cu F.Mask F.Paste))
23 | (pad A2 smd rect (at -2.499873 -2.909957) (size 0.3 0.8) (layers F.Cu F.Mask F.Paste))
24 | (pad A3 smd rect (at -2 -2.909957) (size 0.3 0.8) (layers F.Cu F.Mask F.Paste))
25 | (pad A4 smd rect (at -1.499873 -2.909957) (size 0.3 0.8) (layers F.Cu F.Mask F.Paste))
26 | (pad A5 smd rect (at -1 -2.909957) (size 0.3 0.8) (layers F.Cu F.Mask F.Paste))
27 | (pad A6 smd rect (at -0.499873 -2.909957) (size 0.3 0.8) (layers F.Cu F.Mask F.Paste))
28 | (pad A7 smd rect (at 0.500127 -2.909957) (size 0.3 0.8) (layers F.Cu F.Mask F.Paste))
29 | (pad A8 smd rect (at 1 -2.909957) (size 0.3 0.8) (layers F.Cu F.Mask F.Paste))
30 | (pad A9 smd rect (at 1.500127 -2.909957) (size 0.3 0.8) (layers F.Cu F.Mask F.Paste))
31 | (pad A10 smd rect (at 2 -2.909957) (size 0.3 0.8) (layers F.Cu F.Mask F.Paste))
32 | (pad A11 smd rect (at 2.500127 -2.909957) (size 0.3 0.8) (layers F.Cu F.Mask F.Paste))
33 | (pad A12 smd rect (at 3 -2.909957) (size 0.3 0.8) (layers F.Cu F.Mask F.Paste))
34 | (pad B12 smd rect (at -3.100076 -1.559944) (size 1 0.7) (layers F.Cu F.Mask F.Paste))
35 | (pad B11 smd rect (at -2.249936 -1.559944) (size 0.3 0.7) (layers F.Cu F.Mask F.Paste))
36 | (pad B10 smd rect (at -1.750064 -1.559944) (size 0.3 0.7) (layers F.Cu F.Mask F.Paste))
37 | (pad B9 smd rect (at -1.249936 -1.559944) (size 0.3 0.7) (layers F.Cu F.Mask F.Paste))
38 | (pad B8 smd rect (at -0.750064 -1.559944) (size 0.3 0.7) (layers F.Cu F.Mask F.Paste))
39 | (pad B7 smd rect (at -0.249936 -1.559944) (size 0.3 0.7) (layers F.Cu F.Mask F.Paste))
40 | (pad B6 smd rect (at 0.249936 -1.559944) (size 0.3 0.7) (layers F.Cu F.Mask F.Paste))
41 | (pad B5 smd rect (at 0.750064 -1.559944) (size 0.3 0.7) (layers F.Cu F.Mask F.Paste))
42 | (pad B4 smd rect (at 1.249936 -1.559944) (size 0.3 0.7) (layers F.Cu F.Mask F.Paste))
43 | (pad B3 smd rect (at 1.750064 -1.559944) (size 0.3 0.7) (layers F.Cu F.Mask F.Paste))
44 | (pad B2 smd rect (at 2.249936 -1.559944) (size 0.3 0.7) (layers F.Cu F.Mask F.Paste))
45 | (pad B1 smd rect (at 3.100076 -1.559944) (size 1 0.7) (layers F.Cu F.Mask F.Paste))
46 | (pad 0 thru_hole oval (at 4.320041 -2.449962) (size 1 2.1) (drill oval 0.6 1.6) (layers *.Cu *.Mask))
47 | (pad 0 thru_hole oval (at -4.320041 -2.449962) (size 1 2.1) (drill oval 0.6 1.6) (layers *.Cu *.Mask))
48 | (pad 0 thru_hole oval (at -4.320041 2.909957) (size 1 2.6) (drill oval 0.6 2.099975) (layers *.Cu *.Mask))
49 | (pad 0 thru_hole oval (at 4.320041 2.909957) (size 1 2.6) (drill oval 0.6 2.1) (layers *.Cu *.Mask))
50 | (fp_text user REF** (at 0 8.680036) (layer F.Fab)
51 | (effects (font (size 1 1) (thickness 0.15)))
52 | )
53 | (model ./JLC2KiCad_lib.pretty/packages3d/USB-C-SMD_TYPE-C-USB-18.step
54 | (at (xyz 0 0 0))
55 | (scale (xyz 1 1 1))
56 | (rotate (xyz 0 0 0))
57 | )
58 | )
--------------------------------------------------------------------------------
/psvr2-pc/JLC2KiCad_lib.pretty/CONN-SMD_472720001.kicad_mod:
--------------------------------------------------------------------------------
1 | (module "CONN-SMD_472720001" (layer F.Cu) (tedit 65E4BDD1)
2 | (descr "CONN-SMD_472720001 footprint")
3 | (tags "CONN-SMD_472720001 footprint C587824")
4 | (attr through_hole)
5 | (fp_text reference REF** (at 0 -6.689992) (layer F.SilkS)
6 | (effects (font (size 1 1) (thickness 0.15)))
7 | )
8 | (fp_text value CONN-SMD_472720001 (at 0 12.000025) (layer F.Fab)
9 | (effects (font (size 1 1) (thickness 0.15)))
10 | )
11 | (fp_circle (center 8.449962 -5.000127) (end 8.479934 -5.000127) (layer F.SilkS) (width 0.059995))
12 | (fp_circle (center -0.000127 5.589916) (end 0.299848 5.589916) (layer F.Fab) (width 0.6))
13 | (fp_circle (center 5.5 -5.5) (end 5.600076 -5.5) (layer F.Fab) (width 0.2))
14 | (fp_circle (center 7.999873 -5.5) (end 8.199771 -5.5) (layer F.SilkS) (width 0.2))
15 | (fp_line (start -9.000025 10.000025) (end 8.922428 10.000025) (layer F.SilkS) (width 0.254001))
16 | (fp_line (start 8.249809 9.138329) (end 8.249809 9.249809) (layer F.SilkS) (width 0.254001))
17 | (fp_line (start 8.249809 9.249809) (end 9.000025 10.000025) (layer F.SilkS) (width 0.254001))
18 | (fp_line (start -8.250241 9.138329) (end -8.250241 9.250241) (layer F.SilkS) (width 0.254001))
19 | (fp_line (start -8.250241 9.250241) (end -9.000025 10.000025) (layer F.SilkS) (width 0.254001))
20 | (fp_line (start 8.249809 9.138329) (end 8.249809 6) (layer F.SilkS) (width 0.254001))
21 | (fp_line (start -8.250241 9.138329) (end -8.250241 6) (layer F.SilkS) (width 0.254001))
22 | (fp_line (start -8.250241 9.138329) (end 8.249809 9.138329) (layer F.SilkS) (width 0.254001))
23 | (fp_line (start -4.500127 -4.500076) (end -8.250241 -4.500076) (layer F.SilkS) (width 0.254001))
24 | (fp_line (start 8.249809 -3.521209) (end 8.249809 -4.500076) (layer F.SilkS) (width 0.254001))
25 | (fp_line (start 8.249809 -4.500076) (end 5.999848 -4.500076) (layer F.SilkS) (width 0.254001))
26 | (fp_line (start 8.249809 3.458776) (end 8.249809 -0.658928) (layer F.SilkS) (width 0.254001))
27 | (fp_line (start -8.250241 -3.521209) (end -8.250241 -4.500076) (layer F.SilkS) (width 0.254001))
28 | (fp_line (start -8.250241 3.458776) (end -8.250241 -0.658928) (layer F.SilkS) (width 0.254001))
29 | (pad 1 smd rect (at 5.5 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
30 | (pad 2 smd rect (at 4.999873 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
31 | (pad 3 smd rect (at 4.5 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
32 | (pad 4 smd rect (at 3.999873 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
33 | (pad 5 smd rect (at 3.5 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
34 | (pad 6 smd rect (at 2.999873 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
35 | (pad 7 smd rect (at 2.5 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
36 | (pad 8 smd rect (at 1.999873 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
37 | (pad 9 smd rect (at 1.5 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
38 | (pad 10 smd rect (at 0.999873 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
39 | (pad 11 smd rect (at 0.499746 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
40 | (pad 12 smd rect (at -0.000127 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
41 | (pad 13 smd rect (at -0.5 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
42 | (pad 14 smd rect (at -1.000127 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
43 | (pad 15 smd rect (at -1.500254 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
44 | (pad 16 smd rect (at -2.000127 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
45 | (pad 17 smd rect (at -2.500254 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
46 | (pad 18 smd rect (at -3.000127 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
47 | (pad 19 smd rect (at -3.500254 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
48 | (pad 20 smd rect (at -4.000127 -4.689992) (size 0.28001 2.4) (layers F.Cu F.Mask F.Paste))
49 | (pad "" np_thru_hole circle (at -0.000127 5.589916) (size 1.500025 1.500025) (drill 1.500025) (layers *.Cu *.Mask))
50 | (pad 21 thru_hole oval (at 8.250064 -2.090043) (size 1.5 2.4) (drill oval 0.700025 1.7) (layers *.Cu *.Mask))
51 | (pad 22 thru_hole oval (at -8.250064 -2.090043) (size 1.5 2.4) (drill oval 0.700025 1.7) (layers *.Cu *.Mask))
52 | (pad 23 thru_hole oval (at -8.250064 4.689992) (size 1.5 2) (drill oval 0.700025 1.2) (layers *.Cu *.Mask))
53 | (pad 24 thru_hole oval (at 8.250064 4.689992) (size 1.5 2) (drill oval 0.700025 1.2) (layers *.Cu *.Mask))
54 | (fp_text user REF** (at 0 14.000025) (layer F.Fab)
55 | (effects (font (size 1 1) (thickness 0.15)))
56 | )
57 | (model ./JLC2KiCad_lib.pretty/packages3d/CONN-SMD_472720001.step
58 | (at (xyz 0 0 0))
59 | (scale (xyz 1 1 1))
60 | (rotate (xyz 0 0 0))
61 | )
62 | )
--------------------------------------------------------------------------------
/psvr2-pc/JLC2KiCad_lib.pretty/USB-SMD_692622030100.kicad_mod:
--------------------------------------------------------------------------------
1 | (footprint "USB-SMD_692622030100" (version 20221018) (generator pcbnew)
2 | (layer "F.Cu")
3 | (descr "USB-SMD_692622030100 footprint")
4 | (tags "USB-SMD_692622030100 footprint C464578")
5 | (attr smd)
6 | (fp_text reference "REF**" (at 0.214503 -3.550927) (layer "F.SilkS")
7 | (effects (font (size 1 1) (thickness 0.15)))
8 | (tstamp 0f28f090-51e2-4091-8fbc-a05f8cf4d69a)
9 | )
10 | (fp_text value "USB-SMD_692622030100" (at 0.214503 6.167564) (layer "F.Fab")
11 | (effects (font (size 1 1) (thickness 0.15)))
12 | (tstamp 207a9ef5-5543-4da9-bc53-781812fef45d)
13 | )
14 | (fp_text user "REF**" (at 0.214503 8.167564) (layer "F.Fab")
15 | (effects (font (size 1 1) (thickness 0.15)))
16 | (tstamp 31ce2129-ca0f-4802-af84-c83cf268c209)
17 | )
18 | (fp_line (start -6.603454 4.119939) (end 7.032461 4.119939)
19 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp ba844752-df33-4245-8b8c-0dfa699538c6))
20 | (fp_line (start -6.450013 -1.550038) (end -6.450013 0.156287)
21 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp a3f23bc4-159e-4daf-bea4-00030e4d043b))
22 | (fp_line (start -6.450013 -1.550038) (end -4.281204 -1.550038)
23 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp dcdf9376-7f8b-48b7-852c-78f2a5bbb95b))
24 | (fp_line (start -6.450013 2.518593) (end -6.450013 3.069952)
25 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp 1c37c918-289a-4110-8fe3-c510092ffb72))
26 | (fp_line (start -6.450013 3.069952) (end -6.450013 3.489942)
27 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp 744626db-d80c-4771-8884-a208aece66f6))
28 | (fp_line (start -6.450013 3.489942) (end -6.450013 3.556363)
29 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp 5d05e1e6-0db4-410e-9dff-70b7f27fb1c5))
30 | (fp_line (start -6.450013 3.489942) (end 6.619964 3.489942)
31 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp a5fcc2c3-8b4b-43e2-8192-089104b7d34d))
32 | (fp_line (start -0.818872 -1.550038) (end 2.418821 -1.550038)
33 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp 23b30547-405e-471c-9158-390b1089d142))
34 | (fp_line (start -0.060833 -1.550927) (end -0.060833 0.028956)
35 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp 39347d17-c742-4a4b-8500-a03ebb2add75))
36 | (fp_line (start -0.060833 0.028956) (end 1.63081 0.028956)
37 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp deb75b55-be13-41f8-be5c-a7be46e1b2da))
38 | (fp_line (start -0.037973 -1.550927) (end -0.060833 -1.550927)
39 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp 71fe1ccd-4fe2-4e55-9d31-c1236bb80d98))
40 | (fp_line (start 1.63081 -1.550927) (end 1.53937 -1.550927)
41 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp 9ef01de4-f6ff-4f00-8b35-72ac61ede1d8))
42 | (fp_line (start 1.63081 0.028956) (end 1.63081 -1.550927)
43 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp 0f8cd0d2-2766-43fa-bdf6-8e9430f6bb4a))
44 | (fp_line (start 5.881153 -1.550038) (end 6.619964 -1.550038)
45 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp c3428655-78b3-4a0e-abb9-6890a3df2788))
46 | (fp_line (start 6.619964 -1.550038) (end 6.619964 0.156287)
47 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp 4135cfc5-623e-4d02-b659-3ec40bc3c74b))
48 | (fp_line (start 6.619964 2.518593) (end 6.619964 3.069952)
49 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp 190a0f9f-f7f8-45b3-91b4-447e1783f536))
50 | (fp_line (start 6.619964 3.069952) (end 6.619964 3.489942)
51 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp c223e4d7-0c77-4e9f-9429-758f31dc5b80))
52 | (fp_line (start 6.773762 3.86124) (end 7.032461 4.119939)
53 | (stroke (width 0.254) (type solid)) (layer "F.SilkS") (tstamp 204c1fa2-ef10-4a24-98c6-52e60610bb4b))
54 | (fp_circle (center -6.550292 -1.512573) (end -6.52032 -1.512573)
55 | (stroke (width 0.059995) (type solid)) (fill none) (layer "F.SilkS") (tstamp 1f3f0aa9-d4c3-4679-801e-e78215d3e2e6))
56 | (fp_circle (center -4.390018 -1.949962) (end -4.263018 -1.949962)
57 | (stroke (width 0.254) (type solid)) (fill none) (layer "F.SilkS") (tstamp 93d595d3-71e8-4a37-b141-fff7a9b28070))
58 | (fp_circle (center -4.049911 -1.800102) (end -3.922911 -1.800102)
59 | (stroke (width 0.254) (type solid)) (fill none) (layer "F.Fab") (tstamp 60b4a176-c795-4cc6-9d9f-d062c684b2c8))
60 | (fp_line (start -6.450013 2.787579) (end -6.450013 4.167564)
61 | (stroke (width 0.254) (type solid)) (layer "User.1") (tstamp 9c43ec9a-e37c-4a64-b0a7-9f10b40ddf32))
62 | (fp_line (start -6.450013 2.787579) (end 6.619964 2.787579)
63 | (stroke (width 0.254) (type solid)) (layer "User.1") (tstamp 59e846a7-d397-4ff4-9b90-d2f187f4dc53))
64 | (fp_line (start 6.619964 2.787579) (end 6.619964 4.157557)
65 | (stroke (width 0.254) (type solid)) (layer "User.1") (tstamp 1bc91b71-e47a-4b0f-a8f1-06f0ee91a939))
66 | (pad "1" smd rect (at -3.850013 -1.337567) (size 0.4 1.350013) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp 7575ff93-ba87-4ff6-9ff9-b147ccacdd07))
67 | (pad "2" smd rect (at -3.200025 -1.337567 180) (size 0.4 1.350013) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp 44c981b9-89f5-465f-aa3f-a9f94aa3a986))
68 | (pad "3" smd rect (at -2.550038 -1.337567) (size 0.4 1.350013) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp 96c23fc3-b914-4108-979b-241e8ad6e729))
69 | (pad "4" smd rect (at -1.900051 -1.337567) (size 0.4 1.350013) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp 3bc4e432-8420-44f1-813f-bdad8c1feae2))
70 | (pad "5" smd rect (at -1.250064 -1.337567) (size 0.4 1.350013) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp eecfda33-366e-4a3a-b1de-b92009300491))
71 | (pad "6" smd rect (at 2.850013 -1.337567) (size 0.4 1.350013) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp 3a89395f-da32-47c7-beb5-d3da0847ffd0))
72 | (pad "7" smd rect (at 3.5 -1.337567 180) (size 0.4 1.350013) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp 35729593-d4b0-4061-95b8-37fc70fe1ad0))
73 | (pad "8" smd rect (at 4.149987 -1.337567) (size 0.4 1.350013) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp f4b06025-8f5f-4d7f-a9a4-6c22db745a46))
74 | (pad "9" smd rect (at 4.799975 -1.337567) (size 0.4 1.350013) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp 41ad3642-b31f-473a-83d6-948056bd03d5))
75 | (pad "10" smd rect (at 5.449962 -1.337567) (size 0.4 1.350013) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp da1263f4-5327-4565-af20-fca16bcf0590))
76 | (pad "11" smd rect (at -6.550038 1.337567) (size 1.8 1.9) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp 2d9739b1-4cc7-40c8-b726-f0c5f1b9cfd1))
77 | (pad "12" smd rect (at -3.749936 1.337567) (size 1.9 1.9) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp e257978f-8ec4-49f8-970d-e679ac1c453e))
78 | (pad "13" smd rect (at -1.35014 1.337567) (size 1.9 1.9) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp 76614baf-0cc8-42ab-bc9e-195245c20473))
79 | (pad "14" smd rect (at 1.449962 1.337567 180) (size 1.8 1.9) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp ecf03ce1-74c3-4882-a110-b2cda0a088b3))
80 | (pad "15" smd rect (at 3.950089 1.337567) (size 1.8 1.9) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp 629583eb-5450-474c-b0d7-5a3669647374))
81 | (pad "16" smd rect (at 6.550038 1.337567) (size 2.3 1.9) (layers "F.Cu" "F.Paste" "F.Mask") (tstamp 4233ffa2-3158-4c0d-a82c-925bbd243982))
82 | (model "./JLC2KiCad_lib.pretty/packages3d/USB-SMD_692622030100.step"
83 | (offset (xyz 0.39 -1.3 1.3))
84 | (scale (xyz 1 1 1))
85 | (rotate (xyz 0 0 0))
86 | )
87 | )
88 |
--------------------------------------------------------------------------------
/firmware/swy-type-c-pd-messages.bt:
--------------------------------------------------------------------------------
1 | //------------------------------------------------
2 | //--- 010 Editor v14.0 Binary Template
3 | //
4 | // File: USB Type-C Power Delivery message format
5 | // Authors: Swyter
6 | // Version: 2024.04.24
7 | // Purpose: Template to visually inspect, understand and validate USB-C PD hex data dumps.
8 | // History: Based on https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/usbctypes/ns-usbctypes-_usbc_pd_request_data_object
9 | //------------------------------------------------
10 |
11 | typedef union _USBC_PD_POWER_DATA_OBJECT {
12 | UINT32 U;
13 | struct {
14 | UINT32 Reserved : 30;
15 | UINT32 Type : 2;
16 | } Common;
17 | struct {
18 | UINT32 MaximumCurrentIn10mA : 10;
19 | UINT32 VoltageIn50mV : 10;
20 | UINT32 PeakCurrent : 2;
21 | UINT32 Reserved1 : 3;
22 | UINT32 DataRoleSwap : 1;
23 | UINT32 UsbCommunicationCapable : 1;
24 | UINT32 ExternallyPowered : 1;
25 | UINT32 UsbSuspendSupported : 1;
26 | UINT32 DualRolePower : 1;
27 | UINT32 FixedSupply : 2;
28 | } FixedSupplyPdo;
29 | struct {
30 | UINT32 MaximumAllowablePowerIn250mW : 10;
31 | UINT32 MinimumVoltageIn50mV : 10;
32 | UINT32 MaximumVoltageIn50mV : 10;
33 | UINT32 Battery : 2;
34 | } BatterySupplyPdo;
35 | struct {
36 | UINT32 MaximumCurrentIn10mA : 10;
37 | UINT32 MinimumVoltageIn50mV : 10;
38 | UINT32 MaximumVoltageIn50mV : 10;
39 | UINT32 VariableSupportNonBattery : 2;
40 | } VariableSupplyNonBatteryPdo;
41 | struct {
42 | UINT32 MaximumCurrentIn50mA : 7;
43 | UINT32 Reserved1 : 1;
44 | UINT32 MinimumVoltageIn100mV : 8;
45 | UINT32 Reserved2 : 1;
46 | UINT32 MaximumVoltageIn100mV : 8;
47 | UINT32 Reserved3 : 2;
48 | UINT32 PpsPowerLimited : 1;
49 | UINT32 AugmentedPowerDataObjectType : 2;
50 | UINT32 AugmentedPowerDataObject : 2;
51 | } ProgrammablePowerSupplyApdo;
52 | struct {
53 | UINT32 OperationalCurrentIn10mA : 10;
54 | UINT32 VoltageIn50mV : 10;
55 | UINT32 Reserved : 5;
56 | UINT32 DataRoleSwap : 1;
57 | UINT32 UsbCommunicationCapable : 1;
58 | UINT32 ExternallyPowered : 1;
59 | UINT32 HigherCapability : 1;
60 | UINT32 DualRolePower : 1;
61 | UINT32 FixedSupply : 2;
62 | } FixedSupplyPdoSink;
63 | struct {
64 | UINT32 OperationalPowerIn250mW : 10;
65 | UINT32 MinimumVoltageIn50mV : 10;
66 | UINT32 MaximumVoltageIn50mV : 10;
67 | UINT32 Battery : 2;
68 | } BatterySupplyPdoSink;
69 | struct {
70 | UINT32 OperationalCurrentIn10mA : 10;
71 | UINT32 MinimumVoltageIn50mV : 10;
72 | UINT32 MaximumVoltageIn50mV : 10;
73 | UINT32 VariableSupportNonBattery : 2;
74 | } VariableSupplyNonBatteryPdoSink;
75 | } USBC_PD_POWER_DATA_OBJECT ;
76 |
77 | typedef union _USBC_PD_REQUEST_DATA_OBJECT {
78 | UINT32 U;
79 | struct {
80 | UINT32 Reserved1 : 28;
81 | UINT32 ObjectPosition : 3;
82 | UINT32 Reserved2 : 1;
83 | } Common;
84 | struct {
85 | UINT32 MaximumOperatingCurrentIn10mA : 10;
86 | UINT32 OperatingCurrentIn10mA : 10;
87 | UINT32 Reserved1 : 4;
88 | UINT32 NoUsbSuspend : 1;
89 | UINT32 UsbCommunicationCapable : 1;
90 | UINT32 CapabilityMismatch : 1;
91 | UINT32 GiveBackFlag : 1;
92 | UINT32 ObjectPosition : 3;
93 | UINT32 Reserved2 : 1;
94 | } FixedAndVariableRdo;
95 | struct {
96 | UINT32 MaximumOperatingPowerIn250mW : 10;
97 | UINT32 OperatingPowerIn250mW : 10;
98 | UINT32 Reserved1 : 6;
99 | UINT32 CapabilityMismatch : 1;
100 | UINT32 GiveBackFlag : 1;
101 | UINT32 ObjectPosition : 3;
102 | UINT32 Reserved2 : 1;
103 | } BatteryRdo;
104 | struct {
105 | UINT32 OperatingCurrentIn50mA : 7;
106 | UINT32 Reserved1 : 2;
107 | UINT32 OutputVoltageIn20mV : 11;
108 | UINT32 Reserved2 : 3;
109 | UINT32 UnchunkedExtendedMessagesSupported : 1;
110 | UINT32 Reserved3 : 2;
111 | UINT32 CapabilityMismatch : 1;
112 | UINT32 Reserved4 : 1;
113 | UINT32 ObjectPosition : 3;
114 | UINT32 Reserved5 : 1;
115 | } ProgrammableRdo;
116 | } USBC_PD_REQUEST_DATA_OBJECT;
117 |
118 |
119 | enum PD_MSGTYPE_CONTROL /* Control Message */
120 | {
121 | PD_MSGTYPE_GOODCRC = 0x01,
122 | PD_MSGTYPE_GOTOMIN = 0x02,
123 | PD_MSGTYPE_ACCEPT = 0x03,
124 | PD_MSGTYPE_REJECT = 0x04,
125 | PD_MSGTYPE_PING = 0x05,
126 | PD_MSGTYPE_PS_RDY = 0x06,
127 | PD_MSGTYPE_GET_SOURCE_CAP = 0x07,
128 | PD_MSGTYPE_GET_SINK_CAP = 0x08,
129 | PD_MSGTYPE_DR_SWAP = 0x09,
130 | PD_MSGTYPE_PR_SWAP = 0x0A,
131 | PD_MSGTYPE_VCONN_SWAP = 0x0B,
132 | PD_MSGTYPE_WAIT = 0x0C,
133 | PD_MSGTYPE_SOFT_RESET = 0x0D,
134 | PD_MSGTYPE_NOT_SUPPORTED = 0x10,
135 | PD_MSGTYPE_GET_SOURCE_CAP_EXTENDED = 0x11,
136 | PD_MSGTYPE_GET_STATUS = 0x12,
137 | PD_MSGTYPE_FR_SWAP = 0x13,
138 | PD_MSGTYPE_GET_PPS_STATUS = 0x14,
139 | PD_MSGTYPE_GET_COUNTRY_CODES = 0x15,
140 | PD_MSGTYPE_GET_SINK_CAP_EXTENDED = 0x16,
141 | PD_MSGTYPE_GET_SOURCE_INFO = 0x17,
142 | PD_MSGTYPE_GET_REVISION = 0x18
143 | };
144 |
145 | enum PD_MSGTYPE_DATA /* Data Message */
146 | {
147 | PD_MSGTYPE_SOURCE_CAPABILITIES = 0x01,
148 | PD_MSGTYPE_REQUEST = 0x02,
149 | PD_MSGTYPE_BIST = 0x03,
150 | PD_MSGTYPE_SINK_CAPABILITIES = 0x04,
151 | PD_MSGTYPE_BATTERY_STATUS = 0x05,
152 | PD_MSGTYPE_ALERT = 0x06,
153 | PD_MSGTYPE_GET_COUNTRY_INFO = 0x07,
154 | PD_MSGTYPE_ENTER_USB = 0x08,
155 | PD_MSGTYPE_EPR_REQUEST = 0x09,
156 | PD_MSGTYPE_EPR_MODE = 0x0A,
157 | PD_MSGTYPE_SOURCE_INFO = 0x0B,
158 | PD_MSGTYPE_REVISION = 0x0C,
159 | PD_MSGTYPE_VENDOR_DEFINED = 0x0F
160 | };
161 |
162 | enum PD_MSGTYPE_EXT /* Extended Message */
163 | {
164 | PD_MSGTYPE_SOURCE_CAPABILITIES_EXTENDED = 0x01,
165 | PD_MSGTYPE_STATUS = 0x02,
166 | PD_MSGTYPE_GET_BATTERY_CAP = 0x03,
167 | PD_MSGTYPE_GET_BATTERY_STATUS = 0x04,
168 | PD_MSGTYPE_BATTERY_CAPABILITIES = 0x05,
169 | PD_MSGTYPE_GET_MANUFACTURER_INFO = 0x06,
170 | PD_MSGTYPE_MANUFACTURER_INFO = 0x07,
171 | PD_MSGTYPE_SECURITY_REQUEST = 0x08,
172 | PD_MSGTYPE_SECURITY_RESPONSE = 0x09,
173 | PD_MSGTYPE_FIRMWARE_UPDATE_REQUEST = 0x0A,
174 | PD_MSGTYPE_FIRMWARE_UPDATE_RESPONSE = 0x0B,
175 | PD_MSGTYPE_PPS_STATUS = 0x0C,
176 | PD_MSGTYPE_COUNTRY_INFO = 0x0D,
177 | PD_MSGTYPE_COUNTRY_CODES = 0x0E,
178 | PD_MSGTYPE_SINK_CAPABILITIES_EXTENDED = 0x0F,
179 | PD_MSGTYPE_EXTENDED_CONTROL = 0x10,
180 | PD_MSGTYPE_EPR_SOURCE_CAPABILITIES = 0x11,
181 | PD_MSGTYPE_VENDOR_DEFINED_EXTENDED = 0x1E
182 | };
183 |
184 | typedef struct {
185 | if (ReadUShort() & 0x8000) enum PD_MSGTYPE_EXT MessageType : 5;
186 | else if (ReadUShort() & 0x0E00) enum PD_MSGTYPE_DATA MessageType : 5;
187 | else enum PD_MSGTYPE_CONTROL MessageType : 5;
188 |
189 | UINT16 PortDataRole : 1;
190 | UINT16 SpecRevision : 2;
191 | UINT16 PortPowerRoleOrCablePlug : 1;
192 | UINT16 MessageID : 3;
193 | UINT16 NumberOfDataObjects : 3;
194 | UINT16 Extended : 1;
195 | } USBC_PD_HEADER ;
196 |
197 |
198 | struct
199 | {
200 | USBC_PD_HEADER header ;
201 | if (header.MessageType == 1 && header.NumberOfDataObjects > 0) USBC_PD_POWER_DATA_OBJECT dobj_capabilities[header.NumberOfDataObjects];
202 | else if (header.MessageType == 2 && header.NumberOfDataObjects > 0) USBC_PD_REQUEST_DATA_OBJECT dobj_request [header.NumberOfDataObjects];
203 | } message ;
204 |
205 | if (!FEof())
206 | {
207 | UINT32 orig_checksum ; /* swy: crc32 */
208 |
209 | local uint64 data_end_offset = FileSize() - sizeof(uint); /* swy: right until the end, minus the last four bytes of checksum */
210 | local int64 new_checksum = Checksum(CHECKSUM_CRC32, 0, data_end_offset);
211 |
212 | Printf(
213 | "\n[i] Old: %06X,\n New: %6X (%smatch)\n", orig_checksum, new_checksum,
214 | (orig_checksum == new_checksum) ? "" : "didn't "
215 | );
216 |
217 | }
--------------------------------------------------------------------------------
/firmware/fusb302_defines.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ifndef FUSB302_DEFINES
4 | #define FUSB302_DEFINES
5 | #include
6 |
7 | /* I2C addresses of the FUSB302B chips */
8 | #define FUSB302B_ADDR (0x22 /* << 1 */)
9 | #define FUSB302B01_ADDR (0x23 /* << 1 */)
10 | #define FUSB302B10_ADDR (0x24 /* << 1 */)
11 | #define FUSB302B11_ADDR (0x25 /* << 1 */)
12 |
13 | /* Device ID register */
14 | #define FUSB_DEVICE_ID 0x01
15 | #define FUSB_DEVICE_ID_VERSION_ID_SHIFT 4
16 | #define FUSB_DEVICE_ID_VERSION_ID (0xF << FUSB_DEVICE_ID_VERSION_ID_SHIFT)
17 | #define FUSB_DEVICE_ID_PRODUCT_ID_SHIFT 2
18 | #define FUSB_DEVICE_ID_PRODUCT_ID (0x3 << FUSB_DEVICE_ID_PRODUCT_ID_SHIFT)
19 | #define FUSB_DEVICE_ID_REVISION_ID_SHIFT 0
20 | #define FUSB_DEVICE_ID_REVISION_ID (0x3 << FUSB_DEVICE_ID_REVISION_ID_SHIFT)
21 |
22 | /* Switches0 register */
23 | #define FUSB_SWITCHES0 0x02
24 | #define FUSB_SWITCHES0_CC2_PU_EN (1 << 7) /* swy: was PU_EN2 */
25 | #define FUSB_SWITCHES0_CC1_PU_EN (1 << 6) /* swy: was PU_EN1 */
26 | #define FUSB_SWITCHES0_VCONN_CC2 (1 << 5)
27 | #define FUSB_SWITCHES0_VCONN_CC1 (1 << 4)
28 | #define FUSB_SWITCHES0_MEAS_CC2 (1 << 3)
29 | #define FUSB_SWITCHES0_MEAS_CC1 (1 << 2)
30 | #define FUSB_SWITCHES0_CC2_PD_EN (1 << 1) /* swy: was PDWN_2 */
31 | #define FUSB_SWITCHES0_CC1_PD_EN 1 /* swy: was PDWN_1 */
32 |
33 | /* Switches1 register */
34 | #define FUSB_SWITCHES1 0x03
35 | #define FUSB_SWITCHES1_POWERROLE (1 << 7)
36 | #define FUSB_SWITCHES1_SPECREV_SHIFT 5
37 | #define FUSB_SWITCHES1_SPECREV ( 0x3 << FUSB_SWITCHES1_SPECREV_SHIFT)
38 | #define FUSB_SWITCHES1_SPECREV1 (0b10 << FUSB_SWITCHES1_SPECREV_SHIFT) /* swy: added this non-flag one */
39 | #define FUSB_SWITCHES1_SPECREV0 (0b01 << FUSB_SWITCHES1_SPECREV_SHIFT) /* swy: added this non-flag one */
40 | #define FUSB_SWITCHES1_DATAROLE (1 << 4)
41 | #define FUSB_SWITCHES1_AUTO_CRC (1 << 2)
42 | #define FUSB_SWITCHES1_TXCC2_EN (1 << 1)
43 | #define FUSB_SWITCHES1_TXCC1_EN 1
44 |
45 | /* Measure register */
46 | #define FUSB_MEASURE 0x04
47 | #define FUSB_MEASURE_MEAS_VBUS (1 << 6)
48 | #define FUSB_MEASURE_MDAC_SHIFT 0
49 | #define FUSB_MEASURE_MDAC (0x3F << FUSB_MEASURE_MDAC_SHIFT)
50 |
51 | /* Slice register */
52 | #define FUSB_SLICE 0x05
53 | #define FUSB_SLICE_SDAC_HYS_SHIFT 6
54 | #define FUSB_SLICE_SDAC_HYS (0x3 << FUSB_SLICE_SDAC_HYS_SHIFT)
55 | #define FUSB_SLICE_SDAC_SHIFT 0
56 | #define FUSB_SLICE_SDAC (0x3F << FUSB_SLICE_SDAC_SHIFT)
57 |
58 | /* Control0 register */
59 | #define FUSB_CONTROL0 0x06
60 | #define FUSB_CONTROL0_TX_FLUSH (1 << 6)
61 | #define FUSB_CONTROL0_INT_MASK (1 << 5)
62 | #define FUSB_CONTROL0_HOST_CUR_SHIFT 2
63 | #define FUSB_CONTROL0_HOST_CUR ( 0x3 << FUSB_CONTROL0_HOST_CUR_SHIFT)
64 | #define FUSB_CONTROL0_HOST_CUR1 (0b10 << FUSB_CONTROL0_HOST_CUR_SHIFT) /* swy: added this non-flag one */
65 | #define FUSB_CONTROL0_HOST_CUR0 (0b01 << FUSB_CONTROL0_HOST_CUR_SHIFT) /* swy: added this non-flag one */
66 | #define FUSB_CONTROL0_AUTO_PRE (1 << 1)
67 | #define FUSB_CONTROL0_TX_START 1
68 |
69 | /* Control1 register */
70 | #define FUSB_CONTROL1 0x07
71 | #define FUSB_CONTROL1_ENSOP2DB (1 << 6)
72 | #define FUSB_CONTROL1_ENSOP1DB (1 << 5)
73 | #define FUSB_CONTROL1_BIST_MODE2 (1 << 4)
74 | #define FUSB_CONTROL1_RX_FLUSH (1 << 2)
75 | #define FUSB_CONTROL1_ENSOP2 (1 << 1)
76 | #define FUSB_CONTROL1_ENSOP1 1
77 |
78 | /* Control2 register */
79 | #define FUSB_CONTROL2 0x08
80 | #define FUSB_CONTROL2_TOG_SAVE_PWR_SHIFT 6
81 | #define FUSB_CONTROL2_TOG_SAVE_PWR ( 0x3 << FUSB_CONTROL2_TOG_SAVE_PWR_SHIFT)
82 | #define FUSB_CONTROL2_TOG_SAVE_PWR1 (0b10 << FUSB_CONTROL2_TOG_SAVE_PWR_SHIFT) /* swy: added this non-flag one */
83 | #define FUSB_CONTROL2_TOG_SAVE_PWR0 (0b01 << FUSB_CONTROL2_TOG_SAVE_PWR_SHIFT) /* swy: added this non-flag one */
84 | #define FUSB_CONTROL2_TOG_RD_ONLY (1 << 5)
85 | #define FUSB_CONTROL2_WAKE_EN (1 << 3)
86 | #define FUSB_CONTROL2_MODE_SHIFT 1
87 | #define FUSB_CONTROL2_MODE ( 0x3 << FUSB_CONTROL2_MODE_SHIFT)
88 | #define FUSB_CONTROL2_MODE1 (0b10 << FUSB_CONTROL2_MODE_SHIFT) /* swy: added this non-flag one */
89 | #define FUSB_CONTROL2_MODE0 (0b01 << FUSB_CONTROL2_MODE_SHIFT) /* swy: added this non-flag one */
90 | #define FUSB_CONTROL2_TOGGLE 1
91 |
92 | /* Control3 register */
93 | #define FUSB_CONTROL3 0x09
94 | #define FUSB_CONTROL3_SEND_HARD_RESET (1 << 6)
95 | #define FUSB_CONTROL3_BIST_TMODE (1 << 5)
96 | #define FUSB_CONTROL3_AUTO_HARDRESET (1 << 4)
97 | #define FUSB_CONTROL3_AUTO_SOFTRESET (1 << 3)
98 | #define FUSB_CONTROL3_N_RETRIES_SHIFT 1
99 | #define FUSB_CONTROL3_N_RETRIES ( 0x3 << FUSB_CONTROL3_N_RETRIES_SHIFT)
100 | #define FUSB_CONTROL3_N_RETRIES1 (0b10 << FUSB_CONTROL3_N_RETRIES_SHIFT) /* swy: added this non-flag one */
101 | #define FUSB_CONTROL3_N_RETRIES0 (0b01 << FUSB_CONTROL3_N_RETRIES_SHIFT) /* swy: added this non-flag one */
102 | #define FUSB_CONTROL3_AUTO_RETRY 1
103 |
104 | /* Mask1 register */
105 | #define FUSB_MASK1 0x0A
106 | #define FUSB_MASK1_M_VBUSOK (1 << 7)
107 | #define FUSB_MASK1_M_ACTIVITY (1 << 6)
108 | #define FUSB_MASK1_M_COMP_CHNG (1 << 5)
109 | #define FUSB_MASK1_M_CRC_CHK (1 << 4)
110 | #define FUSB_MASK1_M_ALERT (1 << 3)
111 | #define FUSB_MASK1_M_WAKE (1 << 2)
112 | #define FUSB_MASK1_M_COLLISION (1 << 1)
113 | #define FUSB_MASK1_M_BC_LVL (1 << 0)
114 |
115 | /* Power register */
116 | #define FUSB_POWER 0x0B
117 | #define FUSB_POWER_PWR3 (1 << 3)
118 | #define FUSB_POWER_PWR2 (1 << 2)
119 | #define FUSB_POWER_PWR1 (1 << 1)
120 | #define FUSB_POWER_PWR0 1
121 |
122 | /* Reset register */
123 | #define FUSB_RESET 0x0C
124 | #define FUSB_RESET_PD_RESET (1 << 1)
125 | #define FUSB_RESET_SW_RESET 1
126 |
127 | /* OCPreg register */
128 | #define FUSB_OCPREG 0x0D
129 | #define FUSB_OCPREG_OCP_RANGE (1 << 3)
130 | #define FUSB_OCPREG_OCP_CUR_SHIFT 0
131 | #define FUSB_OCPREG_OCP_CUR (0x7 << FUSB_OCPREG_OCP_CUR_SHIFT)
132 |
133 | /* Maska register */
134 | #define FUSB_MASKA 0x0E
135 | #define FUSB_MASKA_M_OCP_TEMP (1 << 7)
136 | #define FUSB_MASKA_M_TOGDONE (1 << 6)
137 | #define FUSB_MASKA_M_SOFTFAIL (1 << 5)
138 | #define FUSB_MASKA_M_RETRYFAIL (1 << 4)
139 | #define FUSB_MASKA_M_HARDSENT (1 << 3)
140 | #define FUSB_MASKA_M_TXSENT (1 << 2)
141 | #define FUSB_MASKA_M_SOFTRST (1 << 1)
142 | #define FUSB_MASKA_M_HARDRST 1
143 |
144 | /* Maskb register */
145 | #define FUSB_MASKB 0x0F
146 | #define FUSB_MASKB_M_GCRCSENT 1
147 |
148 | /* Control4 register */
149 | #define FUSB_CONTROL4 0x10
150 | #define FUSB_CONTROL4_TOG_EXIT_AUD 1
151 |
152 | /* Status0a register */
153 | #define FUSB_STATUS0A 0x3C
154 | #define FUSB_STATUS0A_SOFTFAIL (1 << 5)
155 | #define FUSB_STATUS0A_RETRYFAIL (1 << 4)
156 | #define FUSB_STATUS0A_POWER3 (1 << 3)
157 | #define FUSB_STATUS0A_POWER2 (1 << 2)
158 | #define FUSB_STATUS0A_SOFTRST (1 << 1)
159 | #define FUSB_STATUS0A_HARDRST 1
160 |
161 | /* Status1a register */
162 | #define FUSB_STATUS1A 0x3D
163 | #define FUSB_STATUS1A_TOGSS_SHIFT 3
164 | #define FUSB_STATUS1A_TOGSS (0x7 << FUSB_STATUS1A_TOGSS_SHIFT)
165 | #define FUSB_STATUS1A_RXSOP2DB (1 << 2)
166 | #define FUSB_STATUS1A_RXSOP1DB (1 << 1)
167 | #define FUSB_STATUS1A_RXSOP 1
168 |
169 | /* Interrupta register */
170 | #define FUSB_INTERRUPTA 0x3E
171 | #define FUSB_INTERRUPTA_I_OCP_TEMP (1 << 7)
172 | #define FUSB_INTERRUPTA_I_TOGDONE (1 << 6)
173 | #define FUSB_INTERRUPTA_I_SOFTFAIL (1 << 5)
174 | #define FUSB_INTERRUPTA_I_RETRYFAIL (1 << 4)
175 | #define FUSB_INTERRUPTA_I_HARDSENT (1 << 3)
176 | #define FUSB_INTERRUPTA_I_TXSENT (1 << 2)
177 | #define FUSB_INTERRUPTA_I_SOFTRST (1 << 1)
178 | #define FUSB_INTERRUPTA_I_HARDRST 1
179 |
180 | /* Interruptb register */
181 | #define FUSB_INTERRUPTB 0x3F
182 | #define FUSB_INTERRUPTB_I_GCRCSENT 1
183 |
184 | /* Status0 register */
185 | #define FUSB_STATUS0 0x40
186 | #define FUSB_STATUS0_VBUSOK (1 << 7)
187 | #define FUSB_STATUS0_ACTIVITY (1 << 6)
188 | #define FUSB_STATUS0_COMP (1 << 5)
189 | #define FUSB_STATUS0_CRC_CHK (1 << 4)
190 | #define FUSB_STATUS0_ALERT (1 << 3)
191 | #define FUSB_STATUS0_WAKE (1 << 2)
192 | #define FUSB_STATUS0_BC_LVL_SHIFT 0
193 | #define FUSB_STATUS0_BC_LVL ( 0x3 << FUSB_STATUS0_BC_LVL_SHIFT)
194 | #define FUSB_STATUS0_BC_LVL1 (0b10 << FUSB_STATUS0_BC_LVL_SHIFT) /* swy: added this non-flag one */
195 | #define FUSB_STATUS0_BC_LVL0 (0b01 << FUSB_STATUS0_BC_LVL_SHIFT) /* swy: added this non-flag one */
196 |
197 |
198 | /* Status1 register */
199 | #define FUSB_STATUS1 0x41
200 | #define FUSB_STATUS1_RXSOP2 (1 << 7)
201 | #define FUSB_STATUS1_RXSOP1 (1 << 6)
202 | #define FUSB_STATUS1_RX_EMPTY (1 << 5)
203 | #define FUSB_STATUS1_RX_FULL (1 << 4)
204 | #define FUSB_STATUS1_TX_EMPTY (1 << 3)
205 | #define FUSB_STATUS1_TX_FULL (1 << 2)
206 | #define FUSB_STATUS1_OVRTEMP (1 << 1)
207 | #define FUSB_STATUS1_OCP 1
208 |
209 | /* Interrupt register */
210 | #define FUSB_INTERRUPT 0x42
211 | #define FUSB_INTERRUPT_I_VBUSOK (1 << 7)
212 | #define FUSB_INTERRUPT_I_ACTIVITY (1 << 6)
213 | #define FUSB_INTERRUPT_I_COMP_CHNG (1 << 5)
214 | #define FUSB_INTERRUPT_I_CRC_CHK (1 << 4)
215 | #define FUSB_INTERRUPT_I_ALERT (1 << 3)
216 | #define FUSB_INTERRUPT_I_WAKE (1 << 2)
217 | #define FUSB_INTERRUPT_I_COLLISION (1 << 1)
218 | #define FUSB_INTERRUPT_I_BC_LVL 1
219 |
220 | /* FIFOs register */
221 | #define FUSB_FIFOS 0x43
222 |
223 | #define FUSB_FIFO_TX_TXON 0xA1
224 | #define FUSB_FIFO_TX_SOP1 0x12
225 | #define FUSB_FIFO_TX_SOP2 0x13
226 | #define FUSB_FIFO_TX_SOP3 0x1B
227 | #define FUSB_FIFO_TX_RESET1 0x15
228 | #define FUSB_FIFO_TX_RESET2 0x16
229 | #define FUSB_FIFO_TX_PACKSYM 0x80
230 | #define FUSB_FIFO_TX_JAM_CRC 0xFF
231 | #define FUSB_FIFO_TX_EOP 0x14
232 | #define FUSB_FIFO_TX_TXOFF 0xFE
233 |
234 | #define FUSB_FIFO_RX_TOKEN_BITS 0xE0
235 | #define FUSB_FIFO_RX_SOP 0xE0
236 | #define FUSB_FIFO_RX_SOP1 0xC0
237 | #define FUSB_FIFO_RX_SOP2 0xA0
238 | #define FUSB_FIFO_RX_SOP1DB 0x80
239 | #define FUSB_FIFO_RX_SOP2DB 0x60
240 |
241 | #endif
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | CERN Open Hardware Licence Version 2 - Strongly Reciprocal
2 |
3 |
4 | Preamble
5 |
6 | CERN has developed this licence to promote collaboration among
7 | hardware designers and to provide a legal tool which supports the
8 | freedom to use, study, modify, share and distribute hardware designs
9 | and products based on those designs. Version 2 of the CERN Open
10 | Hardware Licence comes in three variants: CERN-OHL-P (permissive); and
11 | two reciprocal licences: CERN-OHL-W (weakly reciprocal) and this
12 | licence, CERN-OHL-S (strongly reciprocal).
13 |
14 | The CERN-OHL-S is copyright CERN 2020. Anyone is welcome to use it, in
15 | unmodified form only.
16 |
17 | Use of this Licence does not imply any endorsement by CERN of any
18 | Licensor or their designs nor does it imply any involvement by CERN in
19 | their development.
20 |
21 |
22 | 1 Definitions
23 |
24 | 1.1 'Licence' means this CERN-OHL-S.
25 |
26 | 1.2 'Compatible Licence' means
27 |
28 | a) any earlier version of the CERN Open Hardware licence, or
29 |
30 | b) any version of the CERN-OHL-S, or
31 |
32 | c) any licence which permits You to treat the Source to which
33 | it applies as licensed under CERN-OHL-S provided that on
34 | Conveyance of any such Source, or any associated Product You
35 | treat the Source in question as being licensed under
36 | CERN-OHL-S.
37 |
38 | 1.3 'Source' means information such as design materials or digital
39 | code which can be applied to Make or test a Product or to
40 | prepare a Product for use, Conveyance or sale, regardless of its
41 | medium or how it is expressed. It may include Notices.
42 |
43 | 1.4 'Covered Source' means Source that is explicitly made available
44 | under this Licence.
45 |
46 | 1.5 'Product' means any device, component, work or physical object,
47 | whether in finished or intermediate form, arising from the use,
48 | application or processing of Covered Source.
49 |
50 | 1.6 'Make' means to create or configure something, whether by
51 | manufacture, assembly, compiling, loading or applying Covered
52 | Source or another Product or otherwise.
53 |
54 | 1.7 'Available Component' means any part, sub-assembly, library or
55 | code which:
56 |
57 | a) is licensed to You as Complete Source under a Compatible
58 | Licence; or
59 |
60 | b) is available, at the time a Product or the Source containing
61 | it is first Conveyed, to You and any other prospective
62 | licensees
63 |
64 | i) as a physical part with sufficient rights and
65 | information (including any configuration and
66 | programming files and information about its
67 | characteristics and interfaces) to enable it either to
68 | be Made itself, or to be sourced and used to Make the
69 | Product; or
70 | ii) as part of the normal distribution of a tool used to
71 | design or Make the Product.
72 |
73 | 1.8 'Complete Source' means the set of all Source necessary to Make
74 | a Product, in the preferred form for making modifications,
75 | including necessary installation and interfacing information
76 | both for the Product, and for any included Available Components.
77 | If the format is proprietary, it must also be made available in
78 | a format (if the proprietary tool can create it) which is
79 | viewable with a tool available to potential licensees and
80 | licensed under a licence approved by the Free Software
81 | Foundation or the Open Source Initiative. Complete Source need
82 | not include the Source of any Available Component, provided that
83 | You include in the Complete Source sufficient information to
84 | enable a recipient to Make or source and use the Available
85 | Component to Make the Product.
86 |
87 | 1.9 'Source Location' means a location where a Licensor has placed
88 | Covered Source, and which that Licensor reasonably believes will
89 | remain easily accessible for at least three years for anyone to
90 | obtain a digital copy.
91 |
92 | 1.10 'Notice' means copyright, acknowledgement and trademark notices,
93 | Source Location references, modification notices (subsection
94 | 3.3(b)) and all notices that refer to this Licence and to the
95 | disclaimer of warranties that are included in the Covered
96 | Source.
97 |
98 | 1.11 'Licensee' or 'You' means any person exercising rights under
99 | this Licence.
100 |
101 | 1.12 'Licensor' means a natural or legal person who creates or
102 | modifies Covered Source. A person may be a Licensee and a
103 | Licensor at the same time.
104 |
105 | 1.13 'Convey' means to communicate to the public or distribute.
106 |
107 |
108 | 2 Applicability
109 |
110 | 2.1 This Licence governs the use, copying, modification, Conveying
111 | of Covered Source and Products, and the Making of Products. By
112 | exercising any right granted under this Licence, You irrevocably
113 | accept these terms and conditions.
114 |
115 | 2.2 This Licence is granted by the Licensor directly to You, and
116 | shall apply worldwide and without limitation in time.
117 |
118 | 2.3 You shall not attempt to restrict by contract or otherwise the
119 | rights granted under this Licence to other Licensees.
120 |
121 | 2.4 This Licence is not intended to restrict fair use, fair dealing,
122 | or any other similar right.
123 |
124 |
125 | 3 Copying, Modifying and Conveying Covered Source
126 |
127 | 3.1 You may copy and Convey verbatim copies of Covered Source, in
128 | any medium, provided You retain all Notices.
129 |
130 | 3.2 You may modify Covered Source, other than Notices, provided that
131 | You irrevocably undertake to make that modified Covered Source
132 | available from a Source Location should You Convey a Product in
133 | circumstances where the recipient does not otherwise receive a
134 | copy of the modified Covered Source. In each case subsection 3.3
135 | shall apply.
136 |
137 | You may only delete Notices if they are no longer applicable to
138 | the corresponding Covered Source as modified by You and You may
139 | add additional Notices applicable to Your modifications.
140 | Including Covered Source in a larger work is modifying the
141 | Covered Source, and the larger work becomes modified Covered
142 | Source.
143 |
144 | 3.3 You may Convey modified Covered Source (with the effect that You
145 | shall also become a Licensor) provided that You:
146 |
147 | a) retain Notices as required in subsection 3.2;
148 |
149 | b) add a Notice to the modified Covered Source stating that You
150 | have modified it, with the date and brief description of how
151 | You have modified it;
152 |
153 | c) add a Source Location Notice for the modified Covered Source
154 | if You Convey in circumstances where the recipient does not
155 | otherwise receive a copy of the modified Covered Source; and
156 |
157 | d) license the modified Covered Source under the terms and
158 | conditions of this Licence (or, as set out in subsection
159 | 8.3, a later version, if permitted by the licence of the
160 | original Covered Source). Such modified Covered Source must
161 | be licensed as a whole, but excluding Available Components
162 | contained in it, which remain licensed under their own
163 | applicable licences.
164 |
165 |
166 | 4 Making and Conveying Products
167 |
168 | You may Make Products, and/or Convey them, provided that You either
169 | provide each recipient with a copy of the Complete Source or ensure
170 | that each recipient is notified of the Source Location of the Complete
171 | Source. That Complete Source is Covered Source, and You must
172 | accordingly satisfy Your obligations set out in subsection 3.3. If
173 | specified in a Notice, the Product must visibly and securely display
174 | the Source Location on it or its packaging or documentation in the
175 | manner specified in that Notice.
176 |
177 |
178 | 5 Research and Development
179 |
180 | You may Convey Covered Source, modified Covered Source or Products to
181 | a legal entity carrying out development, testing or quality assurance
182 | work on Your behalf provided that the work is performed on terms which
183 | prevent the entity from both using the Source or Products for its own
184 | internal purposes and Conveying the Source or Products or any
185 | modifications to them to any person other than You. Any modifications
186 | made by the entity shall be deemed to be made by You pursuant to
187 | subsection 3.2.
188 |
189 |
190 | 6 DISCLAIMER AND LIABILITY
191 |
192 | 6.1 DISCLAIMER OF WARRANTY -- The Covered Source and any Products
193 | are provided 'as is' and any express or implied warranties,
194 | including, but not limited to, implied warranties of
195 | merchantability, of satisfactory quality, non-infringement of
196 | third party rights, and fitness for a particular purpose or use
197 | are disclaimed in respect of any Source or Product to the
198 | maximum extent permitted by law. The Licensor makes no
199 | representation that any Source or Product does not or will not
200 | infringe any patent, copyright, trade secret or other
201 | proprietary right. The entire risk as to the use, quality, and
202 | performance of any Source or Product shall be with You and not
203 | the Licensor. This disclaimer of warranty is an essential part
204 | of this Licence and a condition for the grant of any rights
205 | granted under this Licence.
206 |
207 | 6.2 EXCLUSION AND LIMITATION OF LIABILITY -- The Licensor shall, to
208 | the maximum extent permitted by law, have no liability for
209 | direct, indirect, special, incidental, consequential, exemplary,
210 | punitive or other damages of any character including, without
211 | limitation, procurement of substitute goods or services, loss of
212 | use, data or profits, or business interruption, however caused
213 | and on any theory of contract, warranty, tort (including
214 | negligence), product liability or otherwise, arising in any way
215 | in relation to the Covered Source, modified Covered Source
216 | and/or the Making or Conveyance of a Product, even if advised of
217 | the possibility of such damages, and You shall hold the
218 | Licensor(s) free and harmless from any liability, costs,
219 | damages, fees and expenses, including claims by third parties,
220 | in relation to such use.
221 |
222 |
223 | 7 Patents
224 |
225 | 7.1 Subject to the terms and conditions of this Licence, each
226 | Licensor hereby grants to You a perpetual, worldwide,
227 | non-exclusive, no-charge, royalty-free, irrevocable (except as
228 | stated in subsections 7.2 and 8.4) patent licence to Make, have
229 | Made, use, offer to sell, sell, import, and otherwise transfer
230 | the Covered Source and Products, where such licence applies only
231 | to those patent claims licensable by such Licensor that are
232 | necessarily infringed by exercising rights under the Covered
233 | Source as Conveyed by that Licensor.
234 |
235 | 7.2 If You institute patent litigation against any entity (including
236 | a cross-claim or counterclaim in a lawsuit) alleging that the
237 | Covered Source or a Product constitutes direct or contributory
238 | patent infringement, or You seek any declaration that a patent
239 | licensed to You under this Licence is invalid or unenforceable
240 | then any rights granted to You under this Licence shall
241 | terminate as of the date such process is initiated.
242 |
243 |
244 | 8 General
245 |
246 | 8.1 If any provisions of this Licence are or subsequently become
247 | invalid or unenforceable for any reason, the remaining
248 | provisions shall remain effective.
249 |
250 | 8.2 You shall not use any of the name (including acronyms and
251 | abbreviations), image, or logo by which the Licensor or CERN is
252 | known, except where needed to comply with section 3, or where
253 | the use is otherwise allowed by law. Any such permitted use
254 | shall be factual and shall not be made so as to suggest any kind
255 | of endorsement or implication of involvement by the Licensor or
256 | its personnel.
257 |
258 | 8.3 CERN may publish updated versions and variants of this Licence
259 | which it considers to be in the spirit of this version, but may
260 | differ in detail to address new problems or concerns. New
261 | versions will be published with a unique version number and a
262 | variant identifier specifying the variant. If the Licensor has
263 | specified that a given variant applies to the Covered Source
264 | without specifying a version, You may treat that Covered Source
265 | as being released under any version of the CERN-OHL with that
266 | variant. If no variant is specified, the Covered Source shall be
267 | treated as being released under CERN-OHL-S. The Licensor may
268 | also specify that the Covered Source is subject to a specific
269 | version of the CERN-OHL or any later version in which case You
270 | may apply this or any later version of CERN-OHL with the same
271 | variant identifier published by CERN.
272 |
273 | 8.4 This Licence shall terminate with immediate effect if You fail
274 | to comply with any of its terms and conditions.
275 |
276 | 8.5 However, if You cease all breaches of this Licence, then Your
277 | Licence from any Licensor is reinstated unless such Licensor has
278 | terminated this Licence by giving You, while You remain in
279 | breach, a notice specifying the breach and requiring You to cure
280 | it within 30 days, and You have failed to come into compliance
281 | in all material respects by the end of the 30 day period. Should
282 | You repeat the breach after receipt of a cure notice and
283 | subsequent reinstatement, this Licence will terminate
284 | immediately and permanently. Section 6 shall continue to apply
285 | after any termination.
286 |
287 | 8.6 This Licence shall not be enforceable except by a Licensor
288 | acting as such, and third party beneficiary rights are
289 | specifically excluded.
290 |
--------------------------------------------------------------------------------
/psvr2-pc/simulation/simulation.kicad_pro:
--------------------------------------------------------------------------------
1 | {
2 | "board": {
3 | "3dviewports": [],
4 | "design_settings": {
5 | "defaults": {
6 | "board_outline_line_width": 0.049999999999999996,
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": 0.762,
38 | "height": 1.524,
39 | "width": 1.524
40 | },
41 | "silk_line_width": 0.09999999999999999,
42 | "silk_text_italic": false,
43 | "silk_text_size_h": 1.0,
44 | "silk_text_size_v": 1.0,
45 | "silk_text_thickness": 0.09999999999999999,
46 | "silk_text_upright": false,
47 | "zones": {
48 | "min_clearance": 0.5
49 | }
50 | },
51 | "diff_pair_dimensions": [],
52 | "drc_exclusions": [],
53 | "meta": {
54 | "version": 2
55 | },
56 | "rule_severities": {
57 | "annular_width": "error",
58 | "clearance": "error",
59 | "connection_width": "warning",
60 | "copper_edge_clearance": "error",
61 | "copper_sliver": "warning",
62 | "courtyards_overlap": "error",
63 | "diff_pair_gap_out_of_range": "error",
64 | "diff_pair_uncoupled_length_too_long": "error",
65 | "drill_out_of_range": "error",
66 | "duplicate_footprints": "warning",
67 | "extra_footprint": "warning",
68 | "footprint": "error",
69 | "footprint_type_mismatch": "ignore",
70 | "hole_clearance": "error",
71 | "hole_near_hole": "error",
72 | "invalid_outline": "error",
73 | "isolated_copper": "warning",
74 | "item_on_disabled_layer": "error",
75 | "items_not_allowed": "error",
76 | "length_out_of_range": "error",
77 | "lib_footprint_issues": "warning",
78 | "lib_footprint_mismatch": "warning",
79 | "malformed_courtyard": "error",
80 | "microvia_drill_out_of_range": "error",
81 | "missing_courtyard": "ignore",
82 | "missing_footprint": "warning",
83 | "net_conflict": "warning",
84 | "npth_inside_courtyard": "ignore",
85 | "padstack": "warning",
86 | "pth_inside_courtyard": "ignore",
87 | "shorting_items": "error",
88 | "silk_edge_clearance": "warning",
89 | "silk_over_copper": "warning",
90 | "silk_overlap": "warning",
91 | "skew_out_of_range": "error",
92 | "solder_mask_bridge": "error",
93 | "starved_thermal": "error",
94 | "text_height": "warning",
95 | "text_thickness": "warning",
96 | "through_hole_pad_without_hole": "error",
97 | "too_many_vias": "error",
98 | "track_dangling": "warning",
99 | "track_width": "error",
100 | "tracks_crossing": "error",
101 | "unconnected_items": "error",
102 | "unresolved_variable": "error",
103 | "via_dangling": "warning",
104 | "zones_intersect": "error"
105 | },
106 | "rules": {
107 | "max_error": 0.005,
108 | "min_clearance": 0.0,
109 | "min_connection": 0.0,
110 | "min_copper_edge_clearance": 0.5,
111 | "min_hole_clearance": 0.25,
112 | "min_hole_to_hole": 0.25,
113 | "min_microvia_diameter": 0.19999999999999998,
114 | "min_microvia_drill": 0.09999999999999999,
115 | "min_resolved_spokes": 2,
116 | "min_silk_clearance": 0.0,
117 | "min_text_height": 0.7999999999999999,
118 | "min_text_thickness": 0.08,
119 | "min_through_hole_diameter": 0.3,
120 | "min_track_width": 0.0,
121 | "min_via_annular_width": 0.09999999999999999,
122 | "min_via_diameter": 0.5,
123 | "solder_mask_to_copper_clearance": 0.0,
124 | "use_height_for_length_calcs": true
125 | },
126 | "teardrop_options": [
127 | {
128 | "td_allow_use_two_tracks": true,
129 | "td_curve_segcount": 5,
130 | "td_on_pad_in_zone": false,
131 | "td_onpadsmd": true,
132 | "td_onroundshapesonly": false,
133 | "td_ontrackend": false,
134 | "td_onviapad": true
135 | }
136 | ],
137 | "teardrop_parameters": [
138 | {
139 | "td_curve_segcount": 0,
140 | "td_height_ratio": 1.0,
141 | "td_length_ratio": 0.5,
142 | "td_maxheight": 2.0,
143 | "td_maxlen": 1.0,
144 | "td_target_name": "td_round_shape",
145 | "td_width_to_size_filter_ratio": 0.9
146 | },
147 | {
148 | "td_curve_segcount": 0,
149 | "td_height_ratio": 1.0,
150 | "td_length_ratio": 0.5,
151 | "td_maxheight": 2.0,
152 | "td_maxlen": 1.0,
153 | "td_target_name": "td_rect_shape",
154 | "td_width_to_size_filter_ratio": 0.9
155 | },
156 | {
157 | "td_curve_segcount": 0,
158 | "td_height_ratio": 1.0,
159 | "td_length_ratio": 0.5,
160 | "td_maxheight": 2.0,
161 | "td_maxlen": 1.0,
162 | "td_target_name": "td_track_end",
163 | "td_width_to_size_filter_ratio": 0.9
164 | }
165 | ],
166 | "track_widths": [],
167 | "via_dimensions": [],
168 | "zones_allow_external_fillets": false
169 | },
170 | "ipc2581": {
171 | "dist": "",
172 | "distpn": "",
173 | "internal_id": "",
174 | "mfg": "",
175 | "mpn": ""
176 | },
177 | "layer_presets": [],
178 | "viewports": []
179 | },
180 | "boards": [],
181 | "cvpcb": {
182 | "equivalence_files": []
183 | },
184 | "erc": {
185 | "erc_exclusions": [],
186 | "meta": {
187 | "version": 0
188 | },
189 | "pin_map": [
190 | [
191 | 0,
192 | 0,
193 | 0,
194 | 0,
195 | 0,
196 | 0,
197 | 1,
198 | 0,
199 | 0,
200 | 0,
201 | 0,
202 | 2
203 | ],
204 | [
205 | 0,
206 | 2,
207 | 0,
208 | 1,
209 | 0,
210 | 0,
211 | 1,
212 | 0,
213 | 2,
214 | 2,
215 | 2,
216 | 2
217 | ],
218 | [
219 | 0,
220 | 0,
221 | 0,
222 | 0,
223 | 0,
224 | 0,
225 | 1,
226 | 0,
227 | 1,
228 | 0,
229 | 1,
230 | 2
231 | ],
232 | [
233 | 0,
234 | 1,
235 | 0,
236 | 0,
237 | 0,
238 | 0,
239 | 1,
240 | 1,
241 | 2,
242 | 1,
243 | 1,
244 | 2
245 | ],
246 | [
247 | 0,
248 | 0,
249 | 0,
250 | 0,
251 | 0,
252 | 0,
253 | 1,
254 | 0,
255 | 0,
256 | 0,
257 | 0,
258 | 2
259 | ],
260 | [
261 | 0,
262 | 0,
263 | 0,
264 | 0,
265 | 0,
266 | 0,
267 | 0,
268 | 0,
269 | 0,
270 | 0,
271 | 0,
272 | 2
273 | ],
274 | [
275 | 1,
276 | 1,
277 | 1,
278 | 1,
279 | 1,
280 | 0,
281 | 1,
282 | 1,
283 | 1,
284 | 1,
285 | 1,
286 | 2
287 | ],
288 | [
289 | 0,
290 | 0,
291 | 0,
292 | 1,
293 | 0,
294 | 0,
295 | 1,
296 | 0,
297 | 0,
298 | 0,
299 | 0,
300 | 2
301 | ],
302 | [
303 | 0,
304 | 2,
305 | 1,
306 | 2,
307 | 0,
308 | 0,
309 | 1,
310 | 0,
311 | 2,
312 | 2,
313 | 2,
314 | 2
315 | ],
316 | [
317 | 0,
318 | 2,
319 | 0,
320 | 1,
321 | 0,
322 | 0,
323 | 1,
324 | 0,
325 | 2,
326 | 0,
327 | 0,
328 | 2
329 | ],
330 | [
331 | 0,
332 | 2,
333 | 1,
334 | 1,
335 | 0,
336 | 0,
337 | 1,
338 | 0,
339 | 2,
340 | 0,
341 | 0,
342 | 2
343 | ],
344 | [
345 | 2,
346 | 2,
347 | 2,
348 | 2,
349 | 2,
350 | 2,
351 | 2,
352 | 2,
353 | 2,
354 | 2,
355 | 2,
356 | 2
357 | ]
358 | ],
359 | "rule_severities": {
360 | "bus_definition_conflict": "error",
361 | "bus_entry_needed": "error",
362 | "bus_to_bus_conflict": "error",
363 | "bus_to_net_conflict": "error",
364 | "conflicting_netclasses": "error",
365 | "different_unit_footprint": "error",
366 | "different_unit_net": "error",
367 | "duplicate_reference": "error",
368 | "duplicate_sheet_names": "error",
369 | "endpoint_off_grid": "warning",
370 | "extra_units": "error",
371 | "global_label_dangling": "warning",
372 | "hier_label_mismatch": "error",
373 | "label_dangling": "error",
374 | "lib_symbol_issues": "warning",
375 | "missing_bidi_pin": "warning",
376 | "missing_input_pin": "warning",
377 | "missing_power_pin": "error",
378 | "missing_unit": "warning",
379 | "multiple_net_names": "warning",
380 | "net_not_bus_member": "warning",
381 | "no_connect_connected": "warning",
382 | "no_connect_dangling": "warning",
383 | "pin_not_connected": "error",
384 | "pin_not_driven": "error",
385 | "pin_to_pin": "warning",
386 | "power_pin_not_driven": "error",
387 | "similar_labels": "warning",
388 | "simulation_model_issue": "ignore",
389 | "unannotated": "error",
390 | "unit_value_mismatch": "error",
391 | "unresolved_variable": "error",
392 | "wire_dangling": "error"
393 | }
394 | },
395 | "libraries": {
396 | "pinned_footprint_libs": [],
397 | "pinned_symbol_libs": []
398 | },
399 | "meta": {
400 | "filename": "simulation.kicad_pro",
401 | "version": 1
402 | },
403 | "net_settings": {
404 | "classes": [
405 | {
406 | "bus_width": 12,
407 | "clearance": 0.2,
408 | "diff_pair_gap": 0.25,
409 | "diff_pair_via_gap": 0.25,
410 | "diff_pair_width": 0.2,
411 | "line_style": 0,
412 | "microvia_diameter": 0.3,
413 | "microvia_drill": 0.1,
414 | "name": "Default",
415 | "pcb_color": "rgba(0, 0, 0, 0.000)",
416 | "schematic_color": "rgba(0, 0, 0, 0.000)",
417 | "track_width": 0.2,
418 | "via_diameter": 0.6,
419 | "via_drill": 0.3,
420 | "wire_width": 6
421 | }
422 | ],
423 | "meta": {
424 | "version": 3
425 | },
426 | "net_colors": null,
427 | "netclass_assignments": null,
428 | "netclass_patterns": []
429 | },
430 | "pcbnew": {
431 | "last_paths": {
432 | "gencad": "",
433 | "idf": "",
434 | "netlist": "",
435 | "plot": "",
436 | "pos_files": "",
437 | "specctra_dsn": "",
438 | "step": "",
439 | "svg": "",
440 | "vrml": ""
441 | },
442 | "page_layout_descr_file": ""
443 | },
444 | "schematic": {
445 | "annotate_start_num": 0,
446 | "bom_fmt_presets": [],
447 | "bom_fmt_settings": {
448 | "field_delimiter": ",",
449 | "keep_line_breaks": false,
450 | "keep_tabs": false,
451 | "name": "CSV",
452 | "ref_delimiter": ",",
453 | "ref_range_delimiter": "",
454 | "string_delimiter": "\""
455 | },
456 | "bom_presets": [],
457 | "bom_settings": {
458 | "exclude_dnp": false,
459 | "fields_ordered": [
460 | {
461 | "group_by": false,
462 | "label": "Reference",
463 | "name": "Reference",
464 | "show": true
465 | },
466 | {
467 | "group_by": true,
468 | "label": "Value",
469 | "name": "Value",
470 | "show": true
471 | },
472 | {
473 | "group_by": false,
474 | "label": "Datasheet",
475 | "name": "Datasheet",
476 | "show": true
477 | },
478 | {
479 | "group_by": false,
480 | "label": "Footprint",
481 | "name": "Footprint",
482 | "show": true
483 | },
484 | {
485 | "group_by": false,
486 | "label": "Qty",
487 | "name": "${QUANTITY}",
488 | "show": true
489 | },
490 | {
491 | "group_by": true,
492 | "label": "DNP",
493 | "name": "${DNP}",
494 | "show": true
495 | }
496 | ],
497 | "filter_string": "",
498 | "group_symbols": true,
499 | "name": "Grouped By Value",
500 | "sort_asc": true,
501 | "sort_field": "Reference"
502 | },
503 | "connection_grid_size": 50.0,
504 | "drawing": {
505 | "dashed_lines_dash_length_ratio": 12.0,
506 | "dashed_lines_gap_length_ratio": 3.0,
507 | "default_line_thickness": 6.0,
508 | "default_text_size": 50.0,
509 | "field_names": [],
510 | "intersheets_ref_own_page": false,
511 | "intersheets_ref_prefix": "",
512 | "intersheets_ref_short": false,
513 | "intersheets_ref_show": false,
514 | "intersheets_ref_suffix": "",
515 | "junction_size_choice": 3,
516 | "label_size_ratio": 0.375,
517 | "operating_point_overlay_i_precision": 3,
518 | "operating_point_overlay_i_range": "~A",
519 | "operating_point_overlay_v_precision": 3,
520 | "operating_point_overlay_v_range": "~V",
521 | "overbar_offset_ratio": 1.23,
522 | "pin_symbol_size": 25.0,
523 | "text_offset_ratio": 0.15
524 | },
525 | "legacy_lib_dir": "",
526 | "legacy_lib_list": [],
527 | "meta": {
528 | "version": 1
529 | },
530 | "net_format_name": "",
531 | "ngspice": {
532 | "fix_include_paths": true,
533 | "meta": {
534 | "version": 0
535 | },
536 | "model_mode": 4,
537 | "workbook_filename": "simulation.wbk"
538 | },
539 | "page_layout_descr_file": "",
540 | "plot_directory": "",
541 | "spice_current_sheet_as_root": false,
542 | "spice_external_command": "spice \"%I\"",
543 | "spice_model_current_sheet_as_root": true,
544 | "spice_save_all_currents": false,
545 | "spice_save_all_dissipations": false,
546 | "spice_save_all_voltages": false,
547 | "subpart_first_id": 65,
548 | "subpart_id_separator": 0
549 | },
550 | "sheets": [
551 | [
552 | "f11bb3d3-5794-4a95-b9a9-d0bd9f1c0d65",
553 | "Root"
554 | ]
555 | ],
556 | "text_variables": {}
557 | }
558 |
--------------------------------------------------------------------------------
/psvr2-pc/psvr2-pc.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": 1.152,
38 | "height": 1.152,
39 | "width": 1.152
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.0
49 | }
50 | },
51 | "diff_pair_dimensions": [
52 | {
53 | "gap": 0.0,
54 | "via_gap": 0.0,
55 | "width": 0.0
56 | },
57 | {
58 | "gap": 0.2032,
59 | "via_gap": 0.0,
60 | "width": 0.2205
61 | }
62 | ],
63 | "drc_exclusions": [
64 | "clearance|37460000|24540000|dfc2c633-a7c6-4c77-934e-c720a9166ef0|48ea1016-f30c-417f-a5d8-8cfec6be02ec",
65 | "clearance|72830000|21760000|a91172b6-8f6a-4bd0-9ba9-2a67878eba0c|48ea1016-f30c-417f-a5d8-8cfec6be02ec",
66 | "lib_footprint_issues|100838000|43688000|27baab4e-9de1-4a95-922c-ce640da23d97|00000000-0000-0000-0000-000000000000",
67 | "lib_footprint_issues|103540000|58816000|bc304f5a-c3cd-4f1f-8abd-8bf49070a9f6|00000000-0000-0000-0000-000000000000",
68 | "lib_footprint_issues|104548095|61450000|178369a4-7b1b-4992-8ef2-a078449d7aa8|00000000-0000-0000-0000-000000000000",
69 | "lib_footprint_issues|108950855|28244800|c6fbf728-0a34-42b1-9498-4de580403bfc|00000000-0000-0000-0000-000000000000",
70 | "lib_footprint_issues|109730000|25730200|57b5b45f-45df-4bc0-9781-2432e5308d73|00000000-0000-0000-0000-000000000000",
71 | "lib_footprint_issues|109732540|23215600|b8f66cb6-b8bf-422a-ac93-085653d623c4|00000000-0000-0000-0000-000000000000",
72 | "lib_footprint_issues|18006219|56388000|42386110-3f87-4c09-919f-a0d28ec8ea99|00000000-0000-0000-0000-000000000000",
73 | "lib_footprint_issues|19400000|35010000|0914ffa5-d8da-43b1-9fda-df33951be899|00000000-0000-0000-0000-000000000000",
74 | "lib_footprint_issues|20384294|74676000|82fbe728-9788-41fc-9ef4-32d190f49afa|00000000-0000-0000-0000-000000000000",
75 | "lib_footprint_issues|28240000|46670000|c478c4ac-3be2-447d-97c8-3a2af31dface|00000000-0000-0000-0000-000000000000",
76 | "lib_footprint_issues|36010000|65750000|948d529c-08fb-4b31-9de4-6a47c73065cc|00000000-0000-0000-0000-000000000000",
77 | "lib_footprint_issues|38735000|60706000|3fd2024f-c060-428d-a355-5a968fc1fee9|00000000-0000-0000-0000-000000000000",
78 | "lib_footprint_issues|40180000|30470000|d65ad7f8-de46-4955-8b62-ac1593271094|00000000-0000-0000-0000-000000000000",
79 | "lib_footprint_issues|42220000|36950000|a44c59c2-0fb9-4490-b50a-fd5dd0b1e9f9|00000000-0000-0000-0000-000000000000",
80 | "lib_footprint_issues|43408600|45847000|1a96ab0e-f124-4a74-9335-a58fcca5539c|00000000-0000-0000-0000-000000000000",
81 | "lib_footprint_issues|43662600|58394600|6f04d26b-19d6-4a1a-a817-5ae7d321b049|00000000-0000-0000-0000-000000000000",
82 | "lib_footprint_issues|44900000|30480000|befebce2-70fc-4200-ad02-44777cfa3514|00000000-0000-0000-0000-000000000000",
83 | "lib_footprint_issues|48361600|48158400|cc56f0fd-f428-4840-b43a-219edf796120|00000000-0000-0000-0000-000000000000",
84 | "lib_footprint_issues|52750000|30480000|848a9fbf-3c2e-4f60-a416-99a7c84a874e|00000000-0000-0000-0000-000000000000",
85 | "lib_footprint_issues|53120000|36930000|94904cf1-3680-46a3-a4cc-2cfbb5f3f6d4|00000000-0000-0000-0000-000000000000",
86 | "lib_footprint_issues|55180000|23130000|f1b253ed-608e-4e37-90d1-8a2ae9e7e8bc|00000000-0000-0000-0000-000000000000",
87 | "lib_footprint_issues|58970000|26660000|1632baa3-5663-4ef2-8e00-e52c2750f704|00000000-0000-0000-0000-000000000000",
88 | "lib_footprint_issues|63230000|30490000|273a02a3-f076-4f35-a14b-994bf0a65957|00000000-0000-0000-0000-000000000000",
89 | "lib_footprint_issues|64000000|36930423|60a2867f-f8c5-480a-bdfb-b9b07226d4d2|00000000-0000-0000-0000-000000000000",
90 | "lib_footprint_issues|71020000|30490000|148fd52c-260e-4bde-8610-729fac601fee|00000000-0000-0000-0000-000000000000",
91 | "lib_footprint_issues|74060000|56010000|0407901d-5e90-4d91-a1f9-909fef9d5fca|00000000-0000-0000-0000-000000000000",
92 | "lib_footprint_issues|74470000|44370000|b9a4b24f-e6bf-4d69-8672-0cc9fa83cc66|00000000-0000-0000-0000-000000000000",
93 | "lib_footprint_issues|74640000|30493175|1694693f-60ce-43bc-adca-0dd74b2a0fef|00000000-0000-0000-0000-000000000000",
94 | "lib_footprint_issues|74720000|17570000|e3bb956f-837b-447f-9991-f67f4c64430c|00000000-0000-0000-0000-000000000000",
95 | "lib_footprint_issues|77920000|30520000|352741cd-e60d-469d-be49-c18f776cb621|00000000-0000-0000-0000-000000000000",
96 | "lib_footprint_issues|91180000|23220000|560fd3a9-6458-4bf2-af3c-5dfeb2b9ff9b|00000000-0000-0000-0000-000000000000",
97 | "silk_edge_clearance|112659980|39350010|e9643f4b-8116-4aeb-8c02-e7cbf9eaf588|85e9dfe3-d919-46de-b6d5-50f927831964",
98 | "silk_edge_clearance|112659980|39350010|e9643f4b-8116-4aeb-8c02-e7cbf9eaf588|a43a36b0-7e97-430d-98a3-87bdd038e761",
99 | "silk_edge_clearance|112659980|47989990|e9643f4b-8116-4aeb-8c02-e7cbf9eaf588|441db4a2-770d-4b88-b232-f996e8dfeb3e",
100 | "silk_edge_clearance|12598276|14609759|c793a42f-3715-4202-9639-4c8a2964e5b1|ed4c7231-5739-4e27-8e0f-734e85b2a591",
101 | "silk_edge_clearance|12598708|31109809|c793a42f-3715-4202-9639-4c8a2964e5b1|75371627-1818-44ae-a045-81eb414aec6f",
102 | "silk_edge_clearance|12700000|14609759|c793a42f-3715-4202-9639-4c8a2964e5b1|08906638-f566-4694-84d1-011ba4f5cde3",
103 | "silk_edge_clearance|12700000|31109809|c793a42f-3715-4202-9639-4c8a2964e5b1|1af83a7e-52df-4633-ba61-1a73bcf355f1",
104 | "silk_edge_clearance|12710188|14609759|c793a42f-3715-4202-9639-4c8a2964e5b1|208681bc-3cac-4354-9f83-a55deeb8d576",
105 | "silk_edge_clearance|12710188|14609759|c793a42f-3715-4202-9639-4c8a2964e5b1|ebb40d23-8500-455a-a32e-bdee2fd9d22f",
106 | "silk_edge_clearance|12710188|31109809|c793a42f-3715-4202-9639-4c8a2964e5b1|ca5d5c3c-81e4-46db-b6f2-9005b96107b0",
107 | "silk_edge_clearance|13853383|40279987|587e6830-9827-4546-9b3b-37d91f876226|a90fc1ba-3d92-49aa-a2df-5daef21aece6",
108 | "silk_edge_clearance|13866682|53349964|c28a6e0a-7d7d-41b9-bbb2-de6da8d69192|90784519-a769-48c4-80db-c52bb37e3bca",
109 | "silk_over_copper|104954925|48120089|b8bd3a8f-99cf-4212-8b24-3043b14d1a27|00000000-0000-0000-0000-000000000000",
110 | "silk_overlap|39171646|49229722|26223b69-dd62-491e-be44-001aea85c249|e47c2f36-5ba8-415b-882e-e48a817c788c",
111 | "silk_overlap|74350000|56540000|873fa35a-1a6b-4d9c-a1bf-1b7e5fef6ca5|4e94ddcc-c007-48c6-bcc1-91efefb61423",
112 | "silk_overlap|74350000|56540000|873fa35a-1a6b-4d9c-a1bf-1b7e5fef6ca5|88bc1424-1a66-4002-aefc-124dfa01a100",
113 | "silk_overlap|74681500|44497500|42f3225d-bdbe-447a-8486-207b547f9179|5270f24c-4beb-4c24-b7a9-1ef4e413daaf",
114 | "silk_overlap|74681500|44497500|7905685c-c50f-4ef4-9886-e61cda16d6c8|5270f24c-4beb-4c24-b7a9-1ef4e413daaf",
115 | "solder_mask_bridge|38368137|21490509|bd99d4cb-5fe4-49b2-b679-0d2f54f1d27a|a91172b6-8f6a-4bd0-9ba9-2a67878eba0c",
116 | "solder_mask_bridge|64576925|47360008|3e03429f-9a1c-47e5-b5bb-edc8ae06bb65|49f4c4b1-e429-4cf2-96ea-00b0f265aa4c",
117 | "text_height|105500000|32150000|9fbec24a-2488-460d-9823-71feb7ee36b9|00000000-0000-0000-0000-000000000000",
118 | "text_height|21310600|41503600|8963aebd-8605-4171-83f5-d6181d419029|00000000-0000-0000-0000-000000000000",
119 | "text_height|32858500|69494400|9b2ccb39-1b71-4ecf-a969-a295b417b759|00000000-0000-0000-0000-000000000000",
120 | "text_height|36287500|69494400|b62b6575-8ec4-4a85-b465-574917c15d4c|00000000-0000-0000-0000-000000000000",
121 | "text_height|39859000|51298000|41779bc2-e873-494e-b473-3c198e43b46c|00000000-0000-0000-0000-000000000000",
122 | "text_height|46939200|42570400|5ba15f39-0556-4153-b4ea-b9a75ffd1e40|00000000-0000-0000-0000-000000000000",
123 | "text_height|53181252|47955200|188cfb62-3b79-480b-adc2-7a90c3b2d0ab|00000000-0000-0000-0000-000000000000",
124 | "text_height|54279800|68072000|0082d3da-67cb-4e20-8a98-9718164aac6e|00000000-0000-0000-0000-000000000000",
125 | "text_height|54483000|71551800|c21b5a76-cc6a-46a0-b25f-78bd61726dd2|00000000-0000-0000-0000-000000000000",
126 | "text_height|72898000|60706000|7ae0a18f-9ed5-40ea-a100-2b0add23f868|00000000-0000-0000-0000-000000000000",
127 | "text_height|73152000|48742600|673509a1-3b1b-478e-bb5d-acfb0cd15f2d|00000000-0000-0000-0000-000000000000",
128 | "text_height|93776800|58318400|85f8b45b-15da-42aa-86dd-ca7e58ec6e86|00000000-0000-0000-0000-000000000000",
129 | "text_height|93776800|60985400|cdf26534-dddb-4b57-a38b-796c505cda8e|00000000-0000-0000-0000-000000000000",
130 | "text_height|97383600|28575000|d3b31a85-aa02-4458-b8fc-d6c03fb43330|00000000-0000-0000-0000-000000000000",
131 | "text_thickness|21310600|41503600|8963aebd-8605-4171-83f5-d6181d419029|00000000-0000-0000-0000-000000000000",
132 | "text_thickness|93776800|58318400|85f8b45b-15da-42aa-86dd-ca7e58ec6e86|00000000-0000-0000-0000-000000000000",
133 | "text_thickness|93776800|60985400|cdf26534-dddb-4b57-a38b-796c505cda8e|00000000-0000-0000-0000-000000000000",
134 | "text_thickness|97383600|28575000|d3b31a85-aa02-4458-b8fc-d6c03fb43330|00000000-0000-0000-0000-000000000000",
135 | "via_dangling|72830000|21760000|a91172b6-8f6a-4bd0-9ba9-2a67878eba0c|00000000-0000-0000-0000-000000000000"
136 | ],
137 | "meta": {
138 | "version": 2
139 | },
140 | "rule_severities": {
141 | "annular_width": "error",
142 | "clearance": "error",
143 | "connection_width": "warning",
144 | "copper_edge_clearance": "error",
145 | "copper_sliver": "warning",
146 | "courtyards_overlap": "error",
147 | "diff_pair_gap_out_of_range": "error",
148 | "diff_pair_uncoupled_length_too_long": "error",
149 | "drill_out_of_range": "error",
150 | "duplicate_footprints": "warning",
151 | "extra_footprint": "warning",
152 | "footprint": "error",
153 | "footprint_type_mismatch": "ignore",
154 | "hole_clearance": "error",
155 | "hole_near_hole": "error",
156 | "invalid_outline": "error",
157 | "isolated_copper": "warning",
158 | "item_on_disabled_layer": "error",
159 | "items_not_allowed": "error",
160 | "length_out_of_range": "error",
161 | "lib_footprint_issues": "warning",
162 | "lib_footprint_mismatch": "warning",
163 | "malformed_courtyard": "error",
164 | "microvia_drill_out_of_range": "error",
165 | "missing_courtyard": "ignore",
166 | "missing_footprint": "warning",
167 | "net_conflict": "warning",
168 | "npth_inside_courtyard": "ignore",
169 | "padstack": "warning",
170 | "pth_inside_courtyard": "ignore",
171 | "shorting_items": "error",
172 | "silk_edge_clearance": "warning",
173 | "silk_over_copper": "warning",
174 | "silk_overlap": "warning",
175 | "skew_out_of_range": "error",
176 | "solder_mask_bridge": "warning",
177 | "starved_thermal": "error",
178 | "text_height": "warning",
179 | "text_thickness": "warning",
180 | "through_hole_pad_without_hole": "error",
181 | "too_many_vias": "error",
182 | "track_dangling": "warning",
183 | "track_width": "error",
184 | "tracks_crossing": "error",
185 | "unconnected_items": "error",
186 | "unresolved_variable": "error",
187 | "via_dangling": "warning",
188 | "zones_intersect": "error"
189 | },
190 | "rules": {
191 | "max_error": 0.005,
192 | "min_clearance": 0.09,
193 | "min_connection": 0.09,
194 | "min_copper_edge_clearance": 0.3,
195 | "min_hole_clearance": 0.19999999999999998,
196 | "min_hole_to_hole": 0.25,
197 | "min_microvia_diameter": 0.19999999999999998,
198 | "min_microvia_drill": 0.09999999999999999,
199 | "min_resolved_spokes": 1,
200 | "min_silk_clearance": 0.0,
201 | "min_text_height": 0.7999999999999999,
202 | "min_text_thickness": 0.08,
203 | "min_through_hole_diameter": 0.3,
204 | "min_track_width": 0.09,
205 | "min_via_annular_width": 0.049999999999999996,
206 | "min_via_diameter": 0.39999999999999997,
207 | "solder_mask_clearance": 0.0,
208 | "solder_mask_min_width": 0.0,
209 | "solder_mask_to_copper_clearance": 0.005,
210 | "use_height_for_length_calcs": true
211 | },
212 | "teardrop_options": [
213 | {
214 | "td_allow_use_two_tracks": true,
215 | "td_curve_segcount": 5,
216 | "td_on_pad_in_zone": false,
217 | "td_onpadsmd": true,
218 | "td_onroundshapesonly": false,
219 | "td_ontrackend": false,
220 | "td_onviapad": true
221 | }
222 | ],
223 | "teardrop_parameters": [
224 | {
225 | "td_curve_segcount": 5,
226 | "td_height_ratio": 1.0,
227 | "td_length_ratio": 0.5,
228 | "td_maxheight": 2.0,
229 | "td_maxlen": 1.0,
230 | "td_target_name": "td_round_shape",
231 | "td_width_to_size_filter_ratio": 0.9
232 | },
233 | {
234 | "td_curve_segcount": 5,
235 | "td_height_ratio": 1.0,
236 | "td_length_ratio": 0.5,
237 | "td_maxheight": 2.0,
238 | "td_maxlen": 1.0,
239 | "td_target_name": "td_rect_shape",
240 | "td_width_to_size_filter_ratio": 0.9
241 | },
242 | {
243 | "td_curve_segcount": 5,
244 | "td_height_ratio": 1.0,
245 | "td_length_ratio": 0.5,
246 | "td_maxheight": 2.0,
247 | "td_maxlen": 1.0,
248 | "td_target_name": "td_track_end",
249 | "td_width_to_size_filter_ratio": 0.9
250 | }
251 | ],
252 | "track_widths": [
253 | 0.0,
254 | 0.2205
255 | ],
256 | "via_dimensions": [
257 | {
258 | "diameter": 0.0,
259 | "drill": 0.0
260 | },
261 | {
262 | "diameter": 0.4,
263 | "drill": 0.3
264 | }
265 | ],
266 | "zones_allow_external_fillets": false
267 | },
268 | "layer_presets": [],
269 | "viewports": []
270 | },
271 | "boards": [],
272 | "cvpcb": {
273 | "equivalence_files": []
274 | },
275 | "erc": {
276 | "erc_exclusions": [],
277 | "meta": {
278 | "version": 0
279 | },
280 | "pin_map": [
281 | [
282 | 0,
283 | 0,
284 | 0,
285 | 0,
286 | 0,
287 | 0,
288 | 1,
289 | 0,
290 | 0,
291 | 0,
292 | 0,
293 | 2
294 | ],
295 | [
296 | 0,
297 | 2,
298 | 0,
299 | 1,
300 | 0,
301 | 0,
302 | 1,
303 | 0,
304 | 2,
305 | 2,
306 | 2,
307 | 2
308 | ],
309 | [
310 | 0,
311 | 0,
312 | 0,
313 | 0,
314 | 0,
315 | 0,
316 | 1,
317 | 0,
318 | 1,
319 | 0,
320 | 1,
321 | 2
322 | ],
323 | [
324 | 0,
325 | 1,
326 | 0,
327 | 0,
328 | 0,
329 | 0,
330 | 1,
331 | 1,
332 | 2,
333 | 1,
334 | 1,
335 | 2
336 | ],
337 | [
338 | 0,
339 | 0,
340 | 0,
341 | 0,
342 | 0,
343 | 0,
344 | 1,
345 | 0,
346 | 0,
347 | 0,
348 | 0,
349 | 2
350 | ],
351 | [
352 | 0,
353 | 0,
354 | 0,
355 | 0,
356 | 0,
357 | 0,
358 | 0,
359 | 0,
360 | 0,
361 | 0,
362 | 0,
363 | 2
364 | ],
365 | [
366 | 1,
367 | 1,
368 | 1,
369 | 1,
370 | 1,
371 | 0,
372 | 1,
373 | 1,
374 | 1,
375 | 1,
376 | 1,
377 | 2
378 | ],
379 | [
380 | 0,
381 | 0,
382 | 0,
383 | 1,
384 | 0,
385 | 0,
386 | 1,
387 | 0,
388 | 0,
389 | 0,
390 | 0,
391 | 2
392 | ],
393 | [
394 | 0,
395 | 2,
396 | 1,
397 | 2,
398 | 0,
399 | 0,
400 | 1,
401 | 0,
402 | 2,
403 | 2,
404 | 2,
405 | 2
406 | ],
407 | [
408 | 0,
409 | 2,
410 | 0,
411 | 1,
412 | 0,
413 | 0,
414 | 1,
415 | 0,
416 | 2,
417 | 0,
418 | 0,
419 | 2
420 | ],
421 | [
422 | 0,
423 | 2,
424 | 1,
425 | 1,
426 | 0,
427 | 0,
428 | 1,
429 | 0,
430 | 2,
431 | 0,
432 | 0,
433 | 2
434 | ],
435 | [
436 | 2,
437 | 2,
438 | 2,
439 | 2,
440 | 2,
441 | 2,
442 | 2,
443 | 2,
444 | 2,
445 | 2,
446 | 2,
447 | 2
448 | ]
449 | ],
450 | "rule_severities": {
451 | "bus_definition_conflict": "error",
452 | "bus_entry_needed": "error",
453 | "bus_to_bus_conflict": "error",
454 | "bus_to_net_conflict": "error",
455 | "conflicting_netclasses": "error",
456 | "different_unit_footprint": "error",
457 | "different_unit_net": "error",
458 | "duplicate_reference": "error",
459 | "duplicate_sheet_names": "error",
460 | "endpoint_off_grid": "warning",
461 | "extra_units": "error",
462 | "global_label_dangling": "warning",
463 | "hier_label_mismatch": "error",
464 | "label_dangling": "error",
465 | "lib_symbol_issues": "warning",
466 | "missing_bidi_pin": "warning",
467 | "missing_input_pin": "warning",
468 | "missing_power_pin": "error",
469 | "missing_unit": "warning",
470 | "multiple_net_names": "warning",
471 | "net_not_bus_member": "warning",
472 | "no_connect_connected": "warning",
473 | "no_connect_dangling": "warning",
474 | "pin_not_connected": "error",
475 | "pin_not_driven": "error",
476 | "pin_to_pin": "error",
477 | "power_pin_not_driven": "error",
478 | "similar_labels": "warning",
479 | "simulation_model_issue": "ignore",
480 | "unannotated": "error",
481 | "unit_value_mismatch": "error",
482 | "unresolved_variable": "error",
483 | "wire_dangling": "error"
484 | }
485 | },
486 | "libraries": {
487 | "pinned_footprint_libs": [],
488 | "pinned_symbol_libs": []
489 | },
490 | "meta": {
491 | "filename": "psvr2-pc.kicad_pro",
492 | "version": 1
493 | },
494 | "net_settings": {
495 | "classes": [
496 | {
497 | "bus_width": 12,
498 | "clearance": 0.1,
499 | "diff_pair_gap": 0.25,
500 | "diff_pair_via_gap": 0.25,
501 | "diff_pair_width": 0.2,
502 | "line_style": 0,
503 | "microvia_diameter": 0.3,
504 | "microvia_drill": 0.1,
505 | "name": "Default",
506 | "pcb_color": "rgba(0, 0, 0, 0.000)",
507 | "schematic_color": "rgba(0, 0, 0, 0.000)",
508 | "track_width": 0.25,
509 | "via_diameter": 0.8,
510 | "via_drill": 0.4,
511 | "wire_width": 6
512 | },
513 | {
514 | "bus_width": 12,
515 | "clearance": 0.1,
516 | "diff_pair_gap": 0.2032,
517 | "diff_pair_via_gap": 0.25,
518 | "diff_pair_width": 0.2205,
519 | "line_style": 0,
520 | "microvia_diameter": 0.3,
521 | "microvia_drill": 0.1,
522 | "name": "High speed differential DP (100 Ω ±10% impedance)",
523 | "pcb_color": "rgba(0, 0, 0, 0.000)",
524 | "schematic_color": "rgba(0, 0, 0, 0.000)",
525 | "track_width": 0.2205,
526 | "via_diameter": 0.4,
527 | "via_drill": 0.3,
528 | "wire_width": 6
529 | },
530 | {
531 | "bus_width": 12,
532 | "clearance": 0.1,
533 | "diff_pair_gap": 0.2032,
534 | "diff_pair_via_gap": 0.25,
535 | "diff_pair_width": 0.286,
536 | "line_style": 0,
537 | "microvia_diameter": 0.3,
538 | "microvia_drill": 0.1,
539 | "name": "High speed differential SS (90 Ω ±7Ω impedance)",
540 | "pcb_color": "rgba(0, 0, 0, 0.000)",
541 | "schematic_color": "rgba(0, 0, 0, 0.000)",
542 | "track_width": 0.286,
543 | "via_diameter": 0.4,
544 | "via_drill": 0.3,
545 | "wire_width": 6
546 | },
547 | {
548 | "bus_width": 12,
549 | "clearance": 0.2,
550 | "diff_pair_gap": 0.2032,
551 | "diff_pair_via_gap": 0.25,
552 | "diff_pair_width": 0.2,
553 | "line_style": 0,
554 | "microvia_diameter": 0.3,
555 | "microvia_drill": 0.1,
556 | "name": "Power",
557 | "pcb_color": "rgba(0, 0, 0, 0.000)",
558 | "schematic_color": "rgba(0, 0, 0, 0.000)",
559 | "track_width": 0.4,
560 | "via_diameter": 1.8,
561 | "via_drill": 0.4,
562 | "wire_width": 6
563 | }
564 | ],
565 | "meta": {
566 | "version": 3
567 | },
568 | "net_colors": null,
569 | "netclass_assignments": null,
570 | "netclass_patterns": [
571 | {
572 | "netclass": "High speed differential DP (100 Ω ±10% impedance)",
573 | "pattern": "/ML*"
574 | },
575 | {
576 | "netclass": "High speed differential SS (90 Ω ±7Ω impedance)",
577 | "pattern": "/SS*"
578 | },
579 | {
580 | "netclass": "Power",
581 | "pattern": "/DC_JACK_12V*"
582 | },
583 | {
584 | "netclass": "Power",
585 | "pattern": "/VBUS_*V"
586 | },
587 | {
588 | "netclass": "Power",
589 | "pattern": "/PC_VBUS_*"
590 | },
591 | {
592 | "netclass": "High speed differential SS (90 Ω ±7Ω impedance)",
593 | "pattern": "/PC_USB2_*"
594 | },
595 | {
596 | "netclass": "High speed differential SS (90 Ω ±7Ω impedance)",
597 | "pattern": "/HMD_USB2_*"
598 | }
599 | ]
600 | },
601 | "pcbnew": {
602 | "last_paths": {
603 | "gencad": "",
604 | "idf": "",
605 | "netlist": "",
606 | "specctra_dsn": "",
607 | "step": "",
608 | "vrml": ""
609 | },
610 | "page_layout_descr_file": ""
611 | },
612 | "schematic": {
613 | "annotate_start_num": 0,
614 | "drawing": {
615 | "dashed_lines_dash_length_ratio": 12.0,
616 | "dashed_lines_gap_length_ratio": 3.0,
617 | "default_line_thickness": 6.0,
618 | "default_text_size": 50.0,
619 | "field_names": [],
620 | "intersheets_ref_own_page": false,
621 | "intersheets_ref_prefix": "",
622 | "intersheets_ref_short": false,
623 | "intersheets_ref_show": false,
624 | "intersheets_ref_suffix": "",
625 | "junction_size_choice": 3,
626 | "label_size_ratio": 0.375,
627 | "pin_symbol_size": 25.0,
628 | "text_offset_ratio": 0.15
629 | },
630 | "legacy_lib_dir": "",
631 | "legacy_lib_list": [],
632 | "meta": {
633 | "version": 1
634 | },
635 | "net_format_name": "",
636 | "ngspice": {
637 | "fix_include_paths": true,
638 | "meta": {
639 | "version": 0
640 | },
641 | "model_mode": 0,
642 | "workbook_filename": ""
643 | },
644 | "page_layout_descr_file": "",
645 | "plot_directory": "./",
646 | "spice_current_sheet_as_root": false,
647 | "spice_external_command": "spice \"%I\"",
648 | "spice_model_current_sheet_as_root": true,
649 | "spice_save_all_currents": false,
650 | "spice_save_all_voltages": false,
651 | "subpart_first_id": 65,
652 | "subpart_id_separator": 0
653 | },
654 | "sheets": [
655 | [
656 | "381748c8-fb8a-4e0a-a26e-44fd86369b77",
657 | ""
658 | ]
659 | ],
660 | "text_variables": {}
661 | }
662 |
--------------------------------------------------------------------------------
/firmware/main.c:
--------------------------------------------------------------------------------
1 | /**
2 | * | psdaptwor - an experimental PSVR2 to PC adaptor | firmware
3 | * | created by Swyter
4 | *
5 | * SPDX-License-Identifier: GPL-2.0-or-later
6 | */
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include "pico/stdlib.h"
13 | #include "hardware/gpio.h"
14 | #include "hardware/adc.h"
15 |
16 | #include "pico/binary_info.h"
17 | #include "hardware/i2c.h"
18 |
19 | #include "fusb302_defines.h"
20 | //#include "pd.h"
21 |
22 | /* Main microcontroller chip: https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf
23 | https://datasheets.raspberrypi.com/rp2040/hardware-design-with-rp2040.pdf
24 |
25 | Type-C PD controller chip: https://www.onsemi.com/pdf/datasheet/fusb302b-d.pdf
26 | https://github.com/Ralim/usb-pd/
27 | https://www.ti.com/lit/an/slva704/slva704.pdf (good overview of how the I2C protocol works)
28 | https://github.com/ReclaimerLabs/FUSB302/blob/master/FUSB302.cpp (The Google ChromeOS EC implementation; very clean and well-commented)
29 | https://hackaday.com/2023/02/14/all-about-usb-c-talking-low-level-pd/ (init and receiving PD messages as a UFP/sink)
30 | https://hackaday.com/2023/02/22/all-about-usb-c-replying-low-level-pd/ (sending [accept] messages)
31 | https://github.com/CRImier/AltmodeFriend/blob/main/main.py (RP2040 micropython implementation from the Hackaday author)
32 |
33 | M-LVDS to TTL transceiver chip: http://www.ti.com/lit/gpn/SN65MLVD200 */
34 |
35 | enum psdaptwor_pins
36 | {
37 | PSDAPT_PIN_HMD_TYC_SDA = 0, /* swy: I2C connection to FUSB302B Type-C Power Delivery control chip */
38 | PSDAPT_PIN_HMD_TYC_SCL = 1,
39 | PSDAPT_PIN_HMD_TYC_INT = 2,
40 |
41 | PSDAPT_PIN_PC_LVDS_R = 3, /* swy: M-LVDS transceiver data in-out for both DisplayPort AUX sides */
42 | PSDAPT_PIN_PC_LVDS_RE = 4,
43 | PSDAPT_PIN_PC_LVDS_DR = 5,
44 | PSDAPT_PIN_PC_LVDS_D = 6,
45 |
46 | PSDAPT_PIN_HMD_LVDS_R = 7,
47 | PSDAPT_PIN_HMD_LVDS_RE = 8,
48 | PSDAPT_PIN_HMD_LVDS_DR = 9,
49 | PSDAPT_PIN_HMD_LVDS_D = 10,
50 |
51 | /* -- */
52 |
53 | PSDAPT_PIN_PC_HPD = 11, /* swy: DisplayPort hot-plug detection pulse signal */
54 | // PSDAPT_PIN_12_UNUSED = 12,
55 | // PSDAPT_PIN_13_UNUSED = 13,
56 |
57 | PSDAPT_PIN_LED_CONN_WRONG_ORIENT = 14, /* swy: status LEDS; wrong-type-c-orientation is orange */
58 | PSDAPT_PIN_LED_HMD_IS_READY = 15, /* headset-is-ready is green */
59 |
60 | PSDAPT_PIN_HMD_ENABLE_VBUS_12V = 16, /* swy: control the power switches by software as needed to enable */
61 | PSDAPT_PIN_HMD_ENABLE_VBUS = 17, /* the higher 12V DC jack voltage/5V from PC/off */
62 |
63 | PSDAPT_PIN_HMD_USB2_P = 18, /* swy: connected to the headset's USB 2.0 +/- pair, optional, in case we want to */
64 | PSDAPT_PIN_HMD_USB2_N = 19, /* relay it to the host PC via PIO, or inspect the billboard device */
65 | // PSDAPT_PIN_20_UNUSED = 20,
66 | // PSDAPT_PIN_21_UNUSED = 21,
67 |
68 | PSDAPT_PIN_AUX_TERMINATION_N = 22, /* swy: M-LVDS transceiver software-defined pull-up and pull-down resistors */
69 | PSDAPT_PIN_AUX_TERMINATION_P = 23,
70 | PSDAPT_PIN_PC_AUX_TERMINATION_N = 24,
71 | PSDAPT_PIN_PC_AUX_TERMINATION_P = 25,
72 |
73 | PSDAPT_PIN_DC_JACK_VOLT_SENSE = 26, /* swy: analog-to-digital converter pins */
74 | // PSDAPT_PIN_27_UNUSED = 27,
75 | PSDAPT_PIN_ADC_OPT_A = 28,
76 | PSDAPT_PIN_ADC_OPT_B = 29,
77 | };
78 |
79 | // I2C reserves some addresses for special purposes. We exclude these from the scan.
80 | // These are any addresses of the form 000 0xxx or 111 1xxx
81 |
82 | bool reserved_addr(uint8_t addr) {
83 | return (addr & 0x78) == 0 || (addr & 0x78) == 0x78;
84 | }
85 |
86 |
87 | /* swy: I2C register reading/writing functions from: https://forums.raspberrypi.com/viewtopic.php?p=2040653#p2040598 */
88 | // Read bytes from a register
89 | int i2c_read(
90 | i2c_inst_t *i2c, // i2c0 or i2c1
91 | uint8_t i2c_addr, // 7 bit I2C address
92 | uint8_t reg, // Number of the register to read from
93 | uint8_t *rx_data, // Pointer to block of bytes for data read
94 | uint8_t len // Number of bytes of data to read
95 | ) {
96 | if (i2c_write_blocking(i2c, i2c_addr, ®, 1, true) != 1) {
97 | return PICO_ERROR_GENERIC;
98 | }
99 |
100 | if (i2c_read_blocking(i2c, i2c_addr, rx_data, len, false) != len) {
101 | return PICO_ERROR_GENERIC;
102 | }
103 |
104 | return PICO_OK;
105 | }
106 |
107 | int i2c_read_byte(
108 | i2c_inst_t *i2c, // i2c0 or i2c1
109 | uint8_t i2c_addr, // 7 bit I2C address
110 | uint8_t reg, // Number of the register to read from
111 | uint8_t *rx_data // Pointer to block of bytes for data read
112 | ) {
113 | return i2c_read(i2c, i2c_addr, reg, rx_data, 1);
114 | }
115 |
116 | // Write bytes to a register
117 | int i2c_write(
118 | i2c_inst_t *i2c, // i2c0 or i2c1
119 | uint8_t i2c_addr, // 7 bit I2C address
120 | uint8_t reg, // Number of the register to write to
121 | const uint8_t *tx_data, // Pointer to block of bytes to write
122 | uint8_t len // Length of block of bytes to write
123 | ) {
124 | uint8_t tx_len = len + 1;
125 | uint8_t tx_buf[tx_len];
126 | tx_buf[0] = reg;
127 | memcpy(&tx_buf[1], tx_data, len);
128 |
129 | if (i2c_write_blocking(i2c, i2c_addr, tx_buf, tx_len, false) != tx_len) {
130 | return PICO_ERROR_GENERIC;
131 | }
132 |
133 | return PICO_OK;
134 | }
135 |
136 | int i2c_write_byte(
137 | i2c_inst_t *i2c, // i2c0 or i2c1
138 | uint8_t i2c_addr, // 7 bit I2C address
139 | uint8_t reg, // Number of the register to write to
140 | uint8_t tx_byte // Byte to write
141 | ) {
142 | uint8_t tx_buf = tx_byte; return i2c_write(i2c, i2c_addr, reg, &tx_buf, 1);
143 | }
144 |
145 |
146 | char *fusb_debug_register(uint8_t reg, uint8_t reg_data)
147 | {
148 | uint8_t reg_data_orig = reg_data;
149 |
150 | #define CASE_PRINT(_REG) \
151 | case _REG: printf("[%s]: ", _REG[5]);
152 |
153 | #define PRINT_REG(ARG_PREFIX, ARG_NAME) /* swy: if the flag is set, print it, to see if we need to print a | separator make sure the current flag is set and there's any set data underneath that will be processed afterwards, or we'll just print the number */ \
154 | printf("%s%s", (reg_data & ARG_PREFIX##_##ARG_NAME) ? #ARG_NAME : "", (reg_data & ARG_PREFIX##_##ARG_NAME) && (reg_data & (ARG_PREFIX##_##ARG_NAME - 1)) ? "|" : ""); reg_data &= ~ARG_PREFIX##_##ARG_NAME;
155 |
156 | #define CASE_END() \
157 | if (reg_data != 0 || reg_data_orig==reg_data) printf("%#x, ", reg_data); /* swy: if there's any remaining unparsed data, or no flags have been processed, i.e. it's zero, print the number */ \
158 | else printf( ", "); \
159 | break;
160 |
161 | switch (reg)
162 | {
163 | default:
164 | printf("[??? Unknown register %X], ", reg);
165 | break;
166 |
167 | CASE_PRINT(FUSB_SWITCHES0) {
168 | PRINT_REG(FUSB_SWITCHES0, CC2_PU_EN)
169 | PRINT_REG(FUSB_SWITCHES0, CC1_PU_EN)
170 | PRINT_REG(FUSB_SWITCHES0, VCONN_CC2)
171 | PRINT_REG(FUSB_SWITCHES0, VCONN_CC1)
172 | PRINT_REG(FUSB_SWITCHES0, MEAS_CC2 )
173 | PRINT_REG(FUSB_SWITCHES0, MEAS_CC1 )
174 | PRINT_REG(FUSB_SWITCHES0, CC2_PD_EN)
175 | PRINT_REG(FUSB_SWITCHES0, CC1_PD_EN)
176 | CASE_END()
177 | }
178 |
179 | CASE_PRINT(FUSB_SWITCHES1) {
180 | PRINT_REG(FUSB_SWITCHES1, POWERROLE)
181 | PRINT_REG(FUSB_SWITCHES1, SPECREV1 )
182 | PRINT_REG(FUSB_SWITCHES1, SPECREV0 )
183 | PRINT_REG(FUSB_SWITCHES1, DATAROLE )
184 | PRINT_REG(FUSB_SWITCHES1, AUTO_CRC )
185 | PRINT_REG(FUSB_SWITCHES1, TXCC2_EN )
186 | PRINT_REG(FUSB_SWITCHES1, TXCC1_EN )
187 | CASE_END()
188 | }
189 |
190 | CASE_PRINT(FUSB_CONTROL0) {
191 | PRINT_REG(FUSB_CONTROL0, TX_FLUSH )
192 | PRINT_REG(FUSB_CONTROL0, INT_MASK )
193 | PRINT_REG(FUSB_CONTROL0, HOST_CUR1)
194 | PRINT_REG(FUSB_CONTROL0, HOST_CUR0)
195 | PRINT_REG(FUSB_CONTROL0, AUTO_PRE )
196 | PRINT_REG(FUSB_CONTROL0, TX_START )
197 | CASE_END()
198 | }
199 |
200 | CASE_PRINT(FUSB_CONTROL1) {
201 | PRINT_REG(FUSB_CONTROL1, ENSOP2DB )
202 | PRINT_REG(FUSB_CONTROL1, ENSOP1DB )
203 | PRINT_REG(FUSB_CONTROL1, BIST_MODE2)
204 | PRINT_REG(FUSB_CONTROL1, RX_FLUSH )
205 | PRINT_REG(FUSB_CONTROL1, ENSOP2 )
206 | PRINT_REG(FUSB_CONTROL1, ENSOP1 )
207 | CASE_END()
208 | }
209 |
210 | CASE_PRINT(FUSB_CONTROL2) {
211 | PRINT_REG(FUSB_CONTROL2, TOG_SAVE_PWR1)
212 | PRINT_REG(FUSB_CONTROL2, TOG_SAVE_PWR0)
213 | PRINT_REG(FUSB_CONTROL2, TOG_RD_ONLY )
214 | PRINT_REG(FUSB_CONTROL2, WAKE_EN )
215 | PRINT_REG(FUSB_CONTROL2, MODE1 )
216 | PRINT_REG(FUSB_CONTROL2, MODE0 )
217 | PRINT_REG(FUSB_CONTROL2, TOGGLE )
218 | CASE_END()
219 | }
220 |
221 | CASE_PRINT(FUSB_CONTROL3) {
222 | PRINT_REG(FUSB_CONTROL3, SEND_HARD_RESET)
223 | PRINT_REG(FUSB_CONTROL3, BIST_TMODE )
224 | PRINT_REG(FUSB_CONTROL3, AUTO_HARDRESET )
225 | PRINT_REG(FUSB_CONTROL3, AUTO_SOFTRESET )
226 | PRINT_REG(FUSB_CONTROL3, N_RETRIES1 )
227 | PRINT_REG(FUSB_CONTROL3, N_RETRIES0 )
228 | PRINT_REG(FUSB_CONTROL3, AUTO_RETRY )
229 | CASE_END()
230 | }
231 |
232 | CASE_PRINT(FUSB_POWER) {
233 | PRINT_REG(FUSB_POWER, PWR3)
234 | PRINT_REG(FUSB_POWER, PWR2)
235 | PRINT_REG(FUSB_POWER, PWR1)
236 | PRINT_REG(FUSB_POWER, PWR0)
237 | CASE_END()
238 | }
239 |
240 | CASE_PRINT(FUSB_STATUS0A) {
241 | PRINT_REG(FUSB_STATUS0A, SOFTFAIL )
242 | PRINT_REG(FUSB_STATUS0A, RETRYFAIL)
243 | PRINT_REG(FUSB_STATUS0A, POWER3 )
244 | PRINT_REG(FUSB_STATUS0A, POWER2 )
245 | PRINT_REG(FUSB_STATUS0A, SOFTRST )
246 | PRINT_REG(FUSB_STATUS0A, HARDRST )
247 | CASE_END()
248 | }
249 |
250 | CASE_PRINT(FUSB_STATUS1A) {
251 | PRINT_REG(FUSB_STATUS1A, TOGSS_SHIFT)
252 | PRINT_REG(FUSB_STATUS1A, TOGSS )
253 | PRINT_REG(FUSB_STATUS1A, RXSOP2DB )
254 | PRINT_REG(FUSB_STATUS1A, RXSOP1DB )
255 | PRINT_REG(FUSB_STATUS1A, RXSOP )
256 | CASE_END()
257 | }
258 |
259 | CASE_PRINT(FUSB_INTERRUPTA) {
260 | PRINT_REG(FUSB_INTERRUPTA, I_OCP_TEMP )
261 | PRINT_REG(FUSB_INTERRUPTA, I_TOGDONE )
262 | PRINT_REG(FUSB_INTERRUPTA, I_SOFTFAIL )
263 | PRINT_REG(FUSB_INTERRUPTA, I_RETRYFAIL)
264 | PRINT_REG(FUSB_INTERRUPTA, I_HARDSENT )
265 | PRINT_REG(FUSB_INTERRUPTA, I_TXSENT )
266 | PRINT_REG(FUSB_INTERRUPTA, I_SOFTRST )
267 | PRINT_REG(FUSB_INTERRUPTA, I_HARDRST )
268 | CASE_END()
269 | }
270 |
271 | CASE_PRINT(FUSB_INTERRUPTB) {
272 | PRINT_REG(FUSB_INTERRUPTB, I_GCRCSENT)
273 | CASE_END()
274 | }
275 |
276 | CASE_PRINT(FUSB_STATUS0) {
277 | PRINT_REG(FUSB_STATUS0, VBUSOK )
278 | PRINT_REG(FUSB_STATUS0, ACTIVITY)
279 | PRINT_REG(FUSB_STATUS0, COMP )
280 | PRINT_REG(FUSB_STATUS0, CRC_CHK )
281 | PRINT_REG(FUSB_STATUS0, ALERT )
282 | PRINT_REG(FUSB_STATUS0, WAKE )
283 | PRINT_REG(FUSB_STATUS0, BC_LVL1 )
284 | PRINT_REG(FUSB_STATUS0, BC_LVL0 )
285 | CASE_END()
286 | }
287 |
288 | CASE_PRINT(FUSB_STATUS1) {
289 | PRINT_REG(FUSB_STATUS1, RXSOP2 )
290 | PRINT_REG(FUSB_STATUS1, RXSOP1 )
291 | PRINT_REG(FUSB_STATUS1, RX_EMPTY)
292 | PRINT_REG(FUSB_STATUS1, RX_FULL )
293 | PRINT_REG(FUSB_STATUS1, TX_EMPTY)
294 | PRINT_REG(FUSB_STATUS1, TX_FULL )
295 | PRINT_REG(FUSB_STATUS1, OVRTEMP )
296 | PRINT_REG(FUSB_STATUS1, OCP )
297 | CASE_END()
298 | }
299 |
300 | CASE_PRINT(FUSB_INTERRUPT) {
301 | PRINT_REG(FUSB_INTERRUPT, I_VBUSOK )
302 | PRINT_REG(FUSB_INTERRUPT, I_ACTIVITY )
303 | PRINT_REG(FUSB_INTERRUPT, I_COMP_CHNG)
304 | PRINT_REG(FUSB_INTERRUPT, I_CRC_CHK )
305 | PRINT_REG(FUSB_INTERRUPT, I_ALERT )
306 | PRINT_REG(FUSB_INTERRUPT, I_WAKE )
307 | PRINT_REG(FUSB_INTERRUPT, I_COLLISION)
308 | PRINT_REG(FUSB_INTERRUPT, I_BC_LVL )
309 | CASE_END()
310 | }
311 |
312 | }
313 | #undef CASE_END
314 | #undef PRINT_REG
315 | #undef CASE_PRINT
316 | }
317 |
318 | uint32_t fusb_interrupt_callback_happened = 0;
319 | uint8_t dat_int_a, dat_int_b, dat_int, dat_stat1;
320 | bool run_replug = true;
321 |
322 | absolute_time_t before = 0;
323 |
324 | void fusb_interrupt_callback(uint gpio, uint32_t event_mask)
325 | {
326 | before = get_absolute_time();printf("\nget_absolute_time %lu\n", before);
327 | fusb_interrupt_callback_happened = event_mask;
328 | }
329 |
330 |
331 | int fusb_measure_against(int mdac_val)
332 | {
333 | uint8_t rxdata, ret = i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_MEASURE, FUSB_MEASURE_MEAS_VBUS | (mdac_val & 0b111111)); //printf("f write ret: %#x, counter: %x, comp volt: %f\n", ret, mdac_val, mdac_val * 0.420f);
334 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_STATUS0, &rxdata, 1); //printf("i2c_read FUSB_STATUS0: %#x COMP: %u\n", rxdata, (rxdata & FUSB_STATUS0_COMP));
335 | return (rxdata & FUSB_STATUS0_COMP);
336 | }
337 |
338 | int fusb_measure_vbus_bsearch_comp(const void *a, const void *b)
339 | {
340 | long unsigned int index = (long unsigned int) b;
341 |
342 | if ((fusb_measure_against(index) & FUSB_STATUS0_COMP) && index < (FUSB_MEASURE_MDAC + 1))
343 | return (fusb_measure_against(index + 1) == 0) ? 0 : +1;
344 |
345 | return -1;
346 | }
347 |
348 | float fusb_measure_vbus(void)
349 | {
350 | uint8_t counter = 0, lastrxdata = 0, rxdata = 0, ret = 0;
351 |
352 | uint8_t switchesBackup; i2c_read(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, &switchesBackup, 1); //printf("b read FUSB_SWITCHES0: %#x\n", switchesBackup);
353 | uint8_t measureBackup; i2c_read(i2c_default, FUSB302B_ADDR, FUSB_MEASURE, &measureBackup, 1); //printf("b read FUSB_MEASURE: %#x\n", measureBackup);
354 |
355 | ret = i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, switchesBackup & 0b11110011); //printf("f write ret: %#x\n", ret);
356 |
357 | void *bsearch_ret = bsearch(NULL, NULL, FUSB_MEASURE_MDAC + 1, 1, fusb_measure_vbus_bsearch_comp); counter = (uint32_t) bsearch_ret;
358 |
359 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_MEASURE, measureBackup);
360 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, switchesBackup);
361 |
362 | return counter * 0.420f;
363 | }
364 |
365 | int fusb_compare_cc1_and_cc2(void)
366 | {
367 | uint8_t counter = 0, lastrxdata = 0, rxdata = 0, ret = 0, cc1, cc2;
368 | uint8_t switchesBackup; i2c_read(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, &switchesBackup, 1); printf("b read FUSB_SWITCHES0: %#x\n", switchesBackup);
369 | uint8_t measureBackup; i2c_read(i2c_default, FUSB302B_ADDR, FUSB_MEASURE, &measureBackup, 1); printf("b read FUSB_MEASURE: %#x\n", measureBackup);
370 |
371 | ret = i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, FUSB_SWITCHES0_CC1_PD_EN | FUSB_SWITCHES0_CC2_PD_EN | FUSB_SWITCHES0_MEAS_CC1); printf("cc1 write ret: %#x\n", ret);
372 | ret = i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_MEASURE, 0); printf("cc1 write ret: %#x\n", ret);
373 | sleep_ms(10);
374 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_STATUS0, &rxdata, 1); printf("cc1 i2c_read FUSB_STATUS0: %#x BC_LVL: %u\n", rxdata, (cc1 = rxdata & FUSB_STATUS0_BC_LVL));
375 |
376 | ret = i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, FUSB_SWITCHES0_CC1_PD_EN | FUSB_SWITCHES0_CC2_PD_EN | FUSB_SWITCHES0_MEAS_CC2); printf("cc2 write ret: %#x\n", ret);
377 | ret = i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_MEASURE, 0); printf("cc2 write ret: %#x\n", ret);
378 | sleep_ms(10);
379 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_STATUS0, &rxdata, 1); printf("cc2 i2c_read FUSB_STATUS0: %#x BC_LVL: %u\n", rxdata, (cc2 = rxdata & FUSB_STATUS0_BC_LVL));
380 |
381 |
382 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_MEASURE, measureBackup);
383 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, switchesBackup);
384 |
385 | return cc1 > cc2;
386 | }
387 |
388 |
389 | enum tcpc_cc_pull {
390 | TYPEC_CC_RA = 0,
391 | TYPEC_CC_RP = 1, /* A downstream facing port (DFP), such as a host computer, exposes pull-up terminations, Rp, on its CC pins (CC1 and CC2) */
392 | TYPEC_CC_RD = 2, /* An upstream facing port (UFP), such as a peripheral, exposes pull-down terminations, Rd, on its CC pins. */
393 | TYPEC_CC_OPEN = 3,
394 | };
395 |
396 | enum tcpc_rp_value {
397 | TYPEC_RP_USB = 0,
398 | TYPEC_RP_1A5 = 1,
399 | TYPEC_RP_3A0 = 2,
400 | TYPEC_RP_RESERVED = 3,
401 | };
402 |
403 | int cc_polarity = -1;
404 | int previous_pull = TYPEC_CC_RD;
405 | bool vconn_enabled = false;
406 | int dfp_toggling_on = 0;
407 | int pulling_up = 0;
408 |
409 | int togdone_pullup_cc1 = 0;
410 | int togdone_pullup_cc2 = 0;
411 |
412 | uint cur_message_id = 0;
413 |
414 | int set_polarity(int polarity)
415 | {
416 | /* Port polarity : 0 => CC1 is CC line, 1 => CC2 is CC line */
417 | uint8_t reg;
418 |
419 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, ®);
420 |
421 | /* clear VCONN switch bits */
422 | reg &= ~FUSB_SWITCHES0_VCONN_CC1;
423 | reg &= ~FUSB_SWITCHES0_VCONN_CC2;
424 |
425 | if (vconn_enabled) {
426 | /* set VCONN switch to be non-CC line */
427 | if (polarity)
428 | reg |= FUSB_SWITCHES0_VCONN_CC1;
429 | else
430 | reg |= FUSB_SWITCHES0_VCONN_CC2;
431 | }
432 |
433 | /* clear meas_cc bits (RX line select) */
434 | reg &= ~FUSB_SWITCHES0_MEAS_CC1;
435 | reg &= ~FUSB_SWITCHES0_MEAS_CC2;
436 |
437 | /* set rx polarity */
438 | if (polarity)
439 | reg |= FUSB_SWITCHES0_MEAS_CC2;
440 | else
441 | reg |= FUSB_SWITCHES0_MEAS_CC1;
442 |
443 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, reg);
444 |
445 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES1, ®);
446 |
447 | /* clear tx_cc bits */
448 | reg &= ~FUSB_SWITCHES1_TXCC1_EN;
449 | reg &= ~FUSB_SWITCHES1_TXCC2_EN;
450 |
451 | /* set tx polarity */
452 | if (polarity)
453 | reg |= FUSB_SWITCHES1_TXCC2_EN;
454 | else
455 | reg |= FUSB_SWITCHES1_TXCC1_EN;
456 | #if 1
457 | // Enable auto GoodCRC sending
458 | //reg |= FUSB_SWITCHES1_AUTO_CRC;
459 | //reg |= FUSB_SWITCHES1_SPECREV1; reg &= ~FUSB_SWITCHES1_SPECREV0; /* swy: spec 0b10 */
460 | #endif
461 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES1, reg);
462 |
463 | /* Save the polarity for later */
464 | cc_polarity = polarity;
465 |
466 | return 0;
467 | }
468 |
469 | int set_vconn(int enable)
470 | {
471 | /*
472 | * FUSB302 does not have dedicated VCONN Enable switch.
473 | * We'll get through this by disabling both of the
474 | * VCONN - CC* switches to disable, and enabling the
475 | * saved polarity when enabling.
476 | * Therefore at startup, set_polarity should be called first,
477 | * or else live with the default put into init.
478 | */
479 | uint8_t reg;
480 |
481 | /* save enable state for later use */
482 | vconn_enabled = enable;
483 |
484 | if (enable) {
485 | /* set to saved polarity */
486 | set_polarity(cc_polarity);
487 | } else {
488 |
489 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, ®);
490 |
491 | /* clear VCONN switch bits */
492 | reg &= ~FUSB_SWITCHES0_VCONN_CC1;
493 | reg &= ~FUSB_SWITCHES0_VCONN_CC2;
494 |
495 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, reg);
496 | }
497 |
498 | return 0;
499 | }
500 |
501 | int set_cc(int pull)
502 | {
503 | uint8_t reg;
504 |
505 | /*
506 | * Ensure we aren't in the process of changing CC from the alert
507 | * handler, then cancel any pending toggle-triggered CC change.
508 | */
509 | dfp_toggling_on = 0;
510 | previous_pull = pull;
511 |
512 | /* NOTE: FUSB302 toggles a single pull-up between CC1 and CC2 */
513 | /* NOTE: FUSB302 Does not support Ra. */
514 | switch (pull) {
515 | case TYPEC_CC_RP: /* A downstream facing port (DFP), such as a host computer, exposes pull-up terminations, Rp, on its CC pins (CC1 and CC2) */
516 | /* enable the pull-up we know to be necessary */
517 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, ®);
518 |
519 | reg &= ~(FUSB_SWITCHES0_CC1_PU_EN |
520 | FUSB_SWITCHES0_CC2_PU_EN |
521 | FUSB_SWITCHES0_CC1_PD_EN |
522 | FUSB_SWITCHES0_CC2_PD_EN |
523 | FUSB_SWITCHES0_VCONN_CC1 |
524 | FUSB_SWITCHES0_VCONN_CC2);
525 |
526 | reg |= FUSB_SWITCHES0_CC1_PU_EN |
527 | FUSB_SWITCHES0_CC2_PU_EN;
528 |
529 | if (vconn_enabled)
530 | reg |= togdone_pullup_cc1 ?
531 | FUSB_SWITCHES0_VCONN_CC2 :
532 | FUSB_SWITCHES0_VCONN_CC1;
533 |
534 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, reg);
535 |
536 | pulling_up = 1;
537 | dfp_toggling_on = 0;
538 | break;
539 | case TYPEC_CC_RD: /* An upstream facing port (UFP), such as a peripheral, exposes pull-down terminations, Rd, on its CC pins. */
540 | /* Enable UFP Mode */
541 |
542 | /* turn off toggle */
543 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL2, ®);
544 | reg &= ~FUSB_CONTROL2_TOGGLE;
545 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL2, reg);
546 |
547 | /* enable pull-downs, disable pullups */
548 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, ®);
549 | reg &= ~(FUSB_SWITCHES0_CC1_PU_EN);
550 | reg &= ~(FUSB_SWITCHES0_CC2_PU_EN);
551 | reg |= (FUSB_SWITCHES0_CC1_PD_EN);
552 | reg |= (FUSB_SWITCHES0_CC2_PD_EN);
553 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, reg);
554 |
555 | pulling_up = 0;
556 | dfp_toggling_on = 0;
557 | break;
558 | case TYPEC_CC_OPEN:
559 | /* Disable toggling */
560 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL2, ®);
561 | reg &= ~FUSB_CONTROL2_TOGGLE;
562 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL2, reg);
563 |
564 | /* Ensure manual switches are opened */
565 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, ®);
566 | reg &= ~FUSB_SWITCHES0_CC1_PU_EN;
567 | reg &= ~FUSB_SWITCHES0_CC2_PU_EN;
568 | reg &= ~FUSB_SWITCHES0_CC1_PD_EN;
569 | reg &= ~FUSB_SWITCHES0_CC2_PD_EN;
570 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, reg);
571 |
572 | pulling_up = 0;
573 | dfp_toggling_on = 0;
574 | break;
575 | default:
576 | /* Unsupported... */
577 | return 0;
578 | }
579 | return 0;
580 | }
581 |
582 | int init()
583 | {
584 | uint8_t reg;
585 |
586 | /* set default */
587 | cc_polarity = -1;
588 | previous_pull = TYPEC_CC_RD;
589 |
590 | /* set the voltage threshold for no connect detection (vOpen) */
591 | //this->mdac_vnc = TCPC_REG_MEASURE_MDAC_MV(PD_SRC_DEF_VNC_MV);
592 | /* set the voltage threshold for Rd vs Ra detection */
593 | //this->mdac_rd = TCPC_REG_MEASURE_MDAC_MV(PD_SRC_DEF_RD_THRESH_MV);
594 |
595 | /* Restore default settings */
596 | uint32_t ret = i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_RESET, FUSB_RESET_SW_RESET); printf("b write ret: %#x\n", ret);
597 |
598 | sleep_ms(1);
599 |
600 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_DEVICE_ID, ®, 1); printf("b read 0: %#x\n", reg);
601 | printf("FUSB_DEVICE_ID: revision ID: %#x, Product ID: %#x, Revision ID: %#x\n", reg >> FUSB_DEVICE_ID_VERSION_ID_SHIFT, (reg & 0b1100) >> FUSB_DEVICE_ID_PRODUCT_ID_SHIFT, (reg & 0b0011) >> FUSB_DEVICE_ID_REVISION_ID_SHIFT);
602 |
603 | /* Turn on all power */
604 | ret = i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_POWER, FUSB_POWER_PWR0 | FUSB_POWER_PWR1 | FUSB_POWER_PWR2 | FUSB_POWER_PWR3); printf("b write ret: %#x\n", ret);
605 |
606 | /* Turn on retries and set number of retries */
607 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL2, 0);
608 |
609 | /* Turn on retries and set number of retries */
610 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL3, ®);
611 | reg |= FUSB_CONTROL3_AUTO_RETRY;
612 | reg |= FUSB_CONTROL3_N_RETRIES1 | FUSB_CONTROL3_N_RETRIES0;
613 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL3, reg);
614 |
615 | /* Set interrupt masks */
616 | // Setting to 0 so interrupts are allowed
617 | ret = i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_MASK1, 0); printf("c write ret: %#x\n", ret);
618 | ret = i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_MASKA, 0); printf("d write ret: %#x\n", ret);
619 | ret = i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_MASKB, 0); printf("e write ret: %#x\n", ret);
620 |
621 | /* Interrupt Enable */
622 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL0, ®);
623 | reg &= ~FUSB_CONTROL0_INT_MASK;
624 | ret |= FUSB_CONTROL0_HOST_CUR1 | FUSB_CONTROL0_HOST_CUR0;
625 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL0, reg);
626 |
627 | /* Set VCONN switch defaults */
628 | set_polarity(0);
629 | set_vconn(0);
630 |
631 |
632 | //i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL0, ®); reg |= FUSB_CONTROL0_AUTO_PRE; i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL0, reg);
633 |
634 | /* swy: flush the TXFIFO and RXFIFO */
635 | //i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL0, ®); reg |= FUSB_CONTROL0_TX_FLUSH; i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL0, reg);
636 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL1, ®); reg |= FUSB_CONTROL1_RX_FLUSH; i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL1, reg);
637 |
638 | /* swy: disable the measurement switch so that we can read without glitching the RX FIFO; detect_cc_pin_sink() changes it back and restores it automatically */
639 | //i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, ®);
640 | //reg &= ~(FUSB_SWITCHES0_MEAS_CC1 | FUSB_SWITCHES0_MEAS_CC2);
641 | //i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, reg);
642 |
643 | return 0;
644 | }
645 |
646 | /* bring the FUSB302 out of reset after Hard Reset signaling */
647 | void pd_reset()
648 | {
649 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_RESET, FUSB_RESET_PD_RESET);
650 | }
651 |
652 | enum tcpc_cc_voltage_status {
653 | TYPEC_CC_VOLT_OPEN = 0,
654 | TYPEC_CC_VOLT_RA = 1,
655 | TYPEC_CC_VOLT_RD = 2,
656 | TYPEC_CC_VOLT_SNK_DEF = 5,
657 | TYPEC_CC_VOLT_SNK_1_5 = 6,
658 | TYPEC_CC_VOLT_SNK_3_0 = 7,
659 | };
660 |
661 | /* Convert BC LVL values (in FUSB302) to Type-C CC Voltage Status */
662 | uint8_t convert_bc_lvl(uint8_t bc_lvl)
663 | {
664 | /* assume OPEN unless one of the following conditions is true... */
665 | int ret = TYPEC_CC_VOLT_OPEN;
666 |
667 | if (pulling_up) {
668 | if (bc_lvl == 0x00)
669 | ret = TYPEC_CC_VOLT_RA;
670 | else if (bc_lvl < 0x3)
671 | ret = TYPEC_CC_VOLT_RD;
672 | } else {
673 | if (bc_lvl == 0x1)
674 | ret = TYPEC_CC_VOLT_SNK_DEF;
675 | else if (bc_lvl == 0x2)
676 | ret = TYPEC_CC_VOLT_SNK_1_5;
677 | else if (bc_lvl == 0x3)
678 | ret = TYPEC_CC_VOLT_SNK_3_0;
679 | }
680 |
681 | return ret;
682 | }
683 |
684 |
685 | /* Determine cc pin state for sink */
686 | void detect_cc_pin_sink(int *cc1, int *cc2)
687 | {
688 | uint8_t reg;
689 | int orig_meas_cc1;
690 | int orig_meas_cc2;
691 | uint8_t bc_lvl_cc1;
692 | uint8_t bc_lvl_cc2;
693 |
694 | /*
695 | * Measure CC1 first.
696 | */
697 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, ®);
698 |
699 | /* save original state to be returned to later... */
700 | if (reg & FUSB_SWITCHES0_MEAS_CC1)
701 | orig_meas_cc1 = 1;
702 | else
703 | orig_meas_cc1 = 0;
704 |
705 | if (reg & FUSB_SWITCHES0_MEAS_CC2)
706 | orig_meas_cc2 = 1;
707 | else
708 | orig_meas_cc2 = 0;
709 |
710 | /* Disable CC2 measurement switch, enable CC1 measurement switch */
711 | reg &= ~FUSB_SWITCHES0_MEAS_CC2;
712 | reg |= FUSB_SWITCHES0_MEAS_CC1;
713 |
714 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, reg);
715 |
716 | /* CC1 is now being measured by FUSB302. */
717 |
718 | /* Wait on measurement */
719 | sleep_us(250);
720 |
721 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_STATUS0, &bc_lvl_cc1);
722 |
723 | /* mask away unwanted bits */
724 | bc_lvl_cc1 &= (FUSB_STATUS0_BC_LVL0 | FUSB_STATUS0_BC_LVL1);
725 |
726 | /*
727 | * Measure CC2 next.
728 | */
729 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, ®);
730 |
731 | /* Disable CC1 measurement switch, enable CC2 measurement switch */
732 | reg &= ~FUSB_SWITCHES0_MEAS_CC1;
733 | reg |= FUSB_SWITCHES0_MEAS_CC2;
734 |
735 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, reg);
736 |
737 | /* CC2 is now being measured by FUSB302. */
738 |
739 | /* Wait on measurement */
740 | sleep_us(250);
741 |
742 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_STATUS0, &bc_lvl_cc2);
743 |
744 | /* mask away unwanted bits */
745 | bc_lvl_cc2 &= (FUSB_STATUS0_BC_LVL0 | FUSB_STATUS0_BC_LVL1);
746 |
747 | *cc1 = convert_bc_lvl(bc_lvl_cc1);
748 | *cc2 = convert_bc_lvl(bc_lvl_cc2);
749 |
750 | /* return MEAS_CC1/2 switches to original state */
751 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, ®);
752 | if (orig_meas_cc1)
753 | reg |= FUSB_SWITCHES0_MEAS_CC1;
754 | else
755 | reg &= ~FUSB_SWITCHES0_MEAS_CC1;
756 | if (orig_meas_cc2)
757 | reg |= FUSB_SWITCHES0_MEAS_CC2;
758 | else
759 | reg &= ~FUSB_SWITCHES0_MEAS_CC2;
760 |
761 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, reg);
762 | }
763 |
764 |
765 | #define PD_HEADER_CNT(header) (((header) >> 12) & 7)
766 | #define PD_HEADER_TYPE(header) ((header) & 0xF)
767 | #define PD_HEADER_ID(header) (((header) >> 9) & 7)
768 |
769 | int get_num_bytes(uint16_t header)
770 | {
771 | int rv;
772 |
773 | /* Grab the Number of Data Objects field.*/
774 | rv = PD_HEADER_CNT(header);
775 |
776 | /* Multiply by four to go from 32-bit words -> bytes */
777 | rv *= sizeof(uint32_t) /* swy: 4 */;
778 |
779 | /* Plus 2 for header */
780 | rv += 2;
781 |
782 | return rv;
783 | }
784 |
785 | /*
786 | * Make sure to allocate enough memory for *payload.
787 | *
788 | * Maximum size is (max number of data objects + 1) * 4
789 | * The extra "+1" is for the CRC32 calculation
790 | */
791 | int get_message(uint32_t *payload, uint32_t *head)
792 | {
793 | /*
794 | * this is the buffer that will get the burst-read data
795 | * from the fusb302.
796 | *
797 | * it's re-used in a couple different spots, the worst of which
798 | * is the PD packet (not header) and CRC.
799 | * maximum size necessary = 28 + 4 = 32
800 | */
801 | uint8_t buf[32]; const uint8_t send_reg_buf = FUSB_FIFOS;
802 | int rv = 0;
803 | int len, ret_val = 0;
804 |
805 | /* NOTE: Assuming enough memory has been allocated for payload. */
806 |
807 | /*
808 | * PART 1 OF BURST READ: Write in register address.
809 | * Issue a START, no STOP.
810 | */
811 | if (i2c_write_blocking(i2c_default, FUSB302B_ADDR, &send_reg_buf, 1, true) != 1) { printf("return get_message PART 1; ");
812 | return PICO_ERROR_GENERIC;
813 | }
814 |
815 | /*
816 | * PART 2 OF BURST READ: Read up to the header.
817 | * Issue a repeated START, no STOP.
818 | * only grab three bytes so we can get the header
819 | * and determine how many more bytes we need to read.
820 | */
821 |
822 | int ret = i2c_read_blocking(i2c_default, FUSB302B_ADDR, buf, 3, true); if (buf[0] || buf[1] || buf[2]) //printf("return get_message PART 2; %x %x %x\n", buf[0], buf[1], buf[2]);
823 | if (ret != 3) { printf("return get_message PART 2; %x %x %x", buf[0], buf[1], buf[2]);
824 | return PICO_ERROR_GENERIC;
825 | }
826 |
827 | /* Grab the header */
828 | *head = ((buf[2] << 8) & 0xFF00) | (buf[1] & 0xFF);
829 |
830 | /* figure out packet length, subtract header bytes */
831 | len = get_num_bytes(*head) - 2; //if (len) printf("; get_num_bytes %u; \n", len);
832 |
833 | if ((buf[0] & FUSB_FIFO_RX_TOKEN_BITS) == FUSB_FIFO_RX_SOP)
834 | ret_val = len;
835 | else
836 | ret_val = PICO_ERROR_NO_DATA;
837 |
838 | /*
839 | * PART 3 OF BURST READ: Read everything else.
840 | * No START, but do issue a STOP at the end.
841 | * add 4 to len to read CRC out
842 | */
843 | ret = i2c_read_blocking(i2c_default, FUSB302B_ADDR, buf, len+4, false);
844 | if (ret != len+4) { printf("return get_message PART 3; ");
845 | return PICO_ERROR_GENERIC;
846 | }
847 |
848 | /* return the data */
849 | memcpy(payload, buf, len+4);
850 |
851 | return ret_val;
852 | }
853 |
854 | int send_message(uint16_t head, uint32_t *payload)
855 | {
856 | //i2c_read(i2c_default, FUSB302B_ADDR, FUSB_STATUS1, &dat_stat1, 1); fusb_debug_register(FUSB_STATUS1, dat_stat1 ); puts(NULL);
857 |
858 | /* Flush the TXFIFO */
859 | uint8_t reg = 0; //i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL0, ®); reg |= FUSB_CONTROL0_TX_FLUSH; i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL0, reg);
860 |
861 | /* swy: disable the measurement switch so that we can read without glitching the RX FIFO; detect_cc_pin_sink() changes it back and restores it automatically */
862 | //i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, ®);
863 | //reg &= ~(FUSB_SWITCHES0_MEAS_CC1 | FUSB_SWITCHES0_MEAS_CC2);
864 | //i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, reg);
865 |
866 |
867 | uint32_t total_len_with_header = get_num_bytes(head), payload_len = total_len_with_header - 2;
868 | uint8_t tx_len = 0; uint8_t tx_buf[40] = {0}; //printf("send_message() head=%#6x payload=%#06x total_len_with_header=%x payload_len=%x\n", head, payload, total_len_with_header, payload_len);
869 | tx_buf[tx_len++] = FUSB_FIFOS; /* put register address first for of burst tcpc write; as part of the I2C write; anything after that is written data */
870 |
871 | tx_buf[tx_len++] = FUSB_FIFO_TX_SOP1 /* Sync-1 K-code | From the spec; SOP is an ordered set. */;
872 | tx_buf[tx_len++] = FUSB_FIFO_TX_SOP1 /* Sync-1 K-code | The SOP ordered set is defined as: three Sync-1 K-codes */;
873 | tx_buf[tx_len++] = FUSB_FIFO_TX_SOP1 /* Sync-1 K-code | followed by one Sync-2 K-code (see Table 5.5 “SOP ordered set”). */;
874 | tx_buf[tx_len++] = FUSB_FIFO_TX_SOP2 /* Sync-2 K-code */;
875 |
876 | /* packsym tells the TXFIFO that the next X bytes are payload, and should not be interpreted as special tokens.
877 | The 5 LSBs represent X, the number of bytes. */;
878 | tx_buf[tx_len++] = FUSB_FIFO_TX_PACKSYM | (total_len_with_header & 0x1F);
879 |
880 | memcpy(&tx_buf[tx_len], &head, sizeof(head)); tx_len += sizeof(head); /* swy: write in the header (16-bits) */
881 | memcpy(&tx_buf[tx_len], &payload, payload_len); tx_len += payload_len; /* swy: write the body (multiples of 32-bit "data objects") */
882 |
883 | tx_buf[tx_len++] = FUSB_FIFO_TX_JAM_CRC /* make it generate and add the correct CRC32 for our payload data */;
884 | tx_buf[tx_len++] = FUSB_FIFO_TX_EOP /* EOP K-code | Causes an EOP symbol to be sent when this token reaches the end of the TX FIFO */;
885 |
886 | tx_buf[tx_len++] = FUSB_FIFO_TX_TXOFF; /* swy: make the FUSB32 chip send the packet when it reaches these special tokens; don't ask me why we need to toggle it off first */
887 | tx_buf[tx_len++] = FUSB_FIFO_TX_TXON; //printf("send_message() txbuf: %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n", tx_buf[0], tx_buf[1], tx_buf[2], tx_buf[3], tx_buf[4], tx_buf[5], tx_buf[6], tx_buf[7], tx_buf[8], tx_buf[9], tx_buf[10], tx_buf[11], tx_buf[12], tx_buf[13], tx_buf[14], tx_buf[15]);
888 |
889 | //i2c_read(i2c_default, FUSB302B_ADDR, FUSB_STATUS1, &dat_stat1, 1); fusb_debug_register(FUSB_STATUS1, dat_stat1 ); puts(NULL);
890 |
891 | if (i2c_write_blocking(i2c_default, FUSB302B_ADDR, tx_buf, tx_len, false) != tx_len)
892 | return PICO_ERROR_GENERIC;
893 |
894 | //printf("send_message() txbuf: "); for (int i=0; i < tx_len; i++) printf("%x ", tx_buf[i]); puts(NULL);
895 |
896 | //i2c_read(i2c_default, FUSB302B_ADDR, FUSB_STATUS1, &dat_stat1, 1); fusb_debug_register(FUSB_STATUS1, dat_stat1 ); puts(NULL);
897 |
898 | //i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL0, FUSB_CONTROL0_TX_START);
899 |
900 | //i2c_read(i2c_default, FUSB302B_ADDR, FUSB_STATUS1, &dat_stat1, 1); fusb_debug_register(FUSB_STATUS1, dat_stat1 ); puts(NULL);
901 |
902 | return PICO_OK;
903 | }
904 |
905 | int send_reset_message(void)
906 | {
907 | /* Flush the TXFIFO */
908 | uint8_t reg = 0; //i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL0, ®); reg |= FUSB_CONTROL0_TX_FLUSH; i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL0, reg);
909 |
910 | uint8_t tx_len = 0; uint8_t tx_buf[40] = {0}; //printf("send_message() head=%#6x payload=%#06x total_len_with_header=%x payload_len=%x\n", head, payload, total_len_with_header, payload_len);
911 | tx_buf[tx_len++] = FUSB_FIFOS; /* put register address first for of burst tcpc write; as part of the I2C write; anything after that is written data */
912 |
913 | tx_buf[tx_len++] = FUSB_FIFO_TX_RESET1 /* Sync-1 K-code | From the spec; SOP is an ordered set. */;
914 | tx_buf[tx_len++] = FUSB_FIFO_TX_RESET1 /* Sync-1 K-code | The SOP ordered set is defined as: three Sync-1 K-codes */;
915 | tx_buf[tx_len++] = FUSB_FIFO_TX_RESET1 /* Sync-1 K-code | followed by one Sync-2 K-code (see Table 5.5 “SOP ordered set”). */;
916 | tx_buf[tx_len++] = FUSB_FIFO_TX_RESET2 /* Sync-2 K-code */;
917 |
918 | tx_buf[tx_len++] = FUSB_FIFO_TX_TXOFF; /* swy: make the FUSB32 chip send the packet when it reaches these special tokens; don't ask me why we need to toggle it off first */
919 | tx_buf[tx_len++] = FUSB_FIFO_TX_TXON; //printf("send_message() txbuf: %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n", tx_buf[0], tx_buf[1], tx_buf[2], tx_buf[3], tx_buf[4], tx_buf[5], tx_buf[6], tx_buf[7], tx_buf[8], tx_buf[9], tx_buf[10], tx_buf[11], tx_buf[12], tx_buf[13], tx_buf[14], tx_buf[15]);
920 |
921 | printf("send_message() txbuf: "); for (int i=0; i < tx_len; i++) printf("%x ", tx_buf[i]); puts(NULL);
922 |
923 | if (i2c_write_blocking(i2c_default, FUSB302B_ADDR, tx_buf, tx_len, false) != tx_len)
924 | return PICO_ERROR_GENERIC;
925 |
926 | return PICO_OK;
927 | }
928 |
929 |
930 | static const char *str_pdmsgtype[][30] = {
931 | [0] = { /* Control Message (when the number of data objects is zero) */
932 | [0x01] = "GOODCRC ",
933 | [0x02] = "GOTOMIN ",
934 | [0x03] = "ACCEPT ",
935 | [0x04] = "REJECT ",
936 | [0x05] = "PING ",
937 | [0x06] = "PS_RDY ",
938 | [0x07] = "GET_SOURCE_CAP ",
939 | [0x08] = "GET_SINK_CAP ",
940 | [0x09] = "DR_SWAP ",
941 | [0x0A] = "PR_SWAP ",
942 | [0x0B] = "VCONN_SWAP ",
943 | [0x0C] = "WAIT ",
944 | [0x0D] = "SOFT_RESET ",
945 | [0x10] = "NOT_SUPPORTED ",
946 | [0x11] = "GET_SOURCE_CAP_EXTENDED ",
947 | [0x12] = "GET_STATUS ",
948 | [0x13] = "FR_SWAP ",
949 | [0x14] = "GET_PPS_STATUS ",
950 | [0x15] = "GET_COUNTRY_CODES ",
951 | [0x16] = "GET_SINK_CAP_EXTENDED ",
952 | [0x17] = "GET_SOURCE_INFO ",
953 | [0x18] = "GET_REVISION ",
954 | },
955 | [1] = { /* Data Message */
956 | [0x01] = "SOURCE_CAPABILITIES",
957 | [0x02] = "REQUEST ",
958 | [0x03] = "BIST ",
959 | [0x04] = "SINK_CAPABILITIES ",
960 | [0x05] = "BATTERY_STATUS ",
961 | [0x06] = "ALERT ",
962 | [0x07] = "GET_COUNTRY_INFO ",
963 | [0x08] = "ENTER_USB ",
964 | [0x09] = "EPR_REQUEST ",
965 | [0x0A] = "EPR_MODE ",
966 | [0x0B] = "SOURCE_INFO ",
967 | [0x0C] = "REVISION ",
968 | [0x0F] = "VENDOR_DEFINED ",
969 | }
970 | };
971 |
972 | int main() {
973 | stdio_init_all();
974 | stdio_usb_init();
975 | stdio_usb_connected();
976 | printf("ADC Example, measuring GPIO26\n");
977 |
978 | set_sys_clock_khz(160000, true);
979 |
980 | #ifndef PICO_DEFAULT_LED_PIN
981 | #warning blink example requires a board with a regular LED
982 | #else
983 | const uint LED_PIN = PICO_DEFAULT_LED_PIN;
984 | gpio_init (PSDAPT_PIN_LED_CONN_WRONG_ORIENT);
985 | gpio_set_dir(PSDAPT_PIN_LED_CONN_WRONG_ORIENT, GPIO_OUT);
986 | gpio_put (PSDAPT_PIN_LED_CONN_WRONG_ORIENT, 1);
987 |
988 | gpio_init (PSDAPT_PIN_LED_HMD_IS_READY);
989 | gpio_set_dir(PSDAPT_PIN_LED_HMD_IS_READY, GPIO_OUT);
990 | gpio_put (PSDAPT_PIN_LED_HMD_IS_READY, 1);
991 | #endif
992 |
993 | gpio_init (PSDAPT_PIN_HMD_ENABLE_VBUS);
994 | gpio_set_dir(PSDAPT_PIN_HMD_ENABLE_VBUS, GPIO_OUT);
995 | gpio_put (PSDAPT_PIN_HMD_ENABLE_VBUS, 0);
996 |
997 | gpio_init (PSDAPT_PIN_HMD_ENABLE_VBUS_12V);
998 | gpio_set_dir(PSDAPT_PIN_HMD_ENABLE_VBUS_12V, GPIO_OUT);
999 | gpio_put (PSDAPT_PIN_HMD_ENABLE_VBUS_12V, 0);
1000 |
1001 | gpio_init (PSDAPT_PIN_PC_HPD);
1002 | gpio_set_dir(PSDAPT_PIN_PC_HPD, GPIO_OUT);
1003 | gpio_put (PSDAPT_PIN_PC_HPD, 0);
1004 |
1005 | gpio_init (PSDAPT_PIN_HMD_USB2_P);
1006 | gpio_set_dir (PSDAPT_PIN_HMD_USB2_P, GPIO_IN);
1007 | gpio_disable_pulls(PSDAPT_PIN_HMD_USB2_P);
1008 | gpio_init (PSDAPT_PIN_HMD_USB2_N);
1009 | gpio_set_dir (PSDAPT_PIN_HMD_USB2_N, GPIO_IN);
1010 | gpio_disable_pulls(PSDAPT_PIN_HMD_USB2_N);
1011 |
1012 | sleep_ms(3500);
1013 |
1014 | adc_init();
1015 |
1016 | // Make sure GPIO is high-impedance, no pullups etc
1017 | adc_gpio_init(26);
1018 | // Select ADC input 0 (GPIO26)
1019 | adc_select_input(0);
1020 |
1021 |
1022 | // This example will use I2C0 on the default SDA and SCL pins (GP4, GP5 on a Pico)
1023 | i2c_init(i2c_default, 400000);
1024 | gpio_set_function(PICO_DEFAULT_I2C_SDA_PIN, GPIO_FUNC_I2C);
1025 | gpio_set_function(PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C);
1026 | gpio_pull_up(PICO_DEFAULT_I2C_SDA_PIN);
1027 | gpio_pull_up(PICO_DEFAULT_I2C_SCL_PIN);
1028 | // Make the I2C pins available to picotool
1029 | bi_decl(bi_2pins_with_func(PICO_DEFAULT_I2C_SDA_PIN, PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C));
1030 |
1031 | gpio_set_irq_enabled_with_callback(PSDAPT_PIN_HMD_TYC_INT, GPIO_IRQ_EDGE_FALL, true, fusb_interrupt_callback);
1032 |
1033 |
1034 | printf("\nI2C Bus Scan test\n");
1035 | printf(" 0 1 2 3 4 5 6 7 8 9 A B C D E F\n");
1036 |
1037 | for (int addr = 0; addr < (1 << 7); ++addr) {
1038 | if (addr % 16 == 0) {
1039 | printf("%02x ", addr);
1040 | }
1041 |
1042 | // Perform a 1-byte dummy read from the probe address. If a slave
1043 | // acknowledges this address, the function returns the number of bytes
1044 | // transferred. If the address byte is ignored, the function returns
1045 | // -1.
1046 |
1047 | // Skip over any reserved addresses.
1048 | int ret = 0;
1049 | uint8_t rxdata;
1050 | absolute_time_t timeout = make_timeout_time_ms(50);
1051 |
1052 | if (reserved_addr(addr))
1053 | ret = PICO_ERROR_GENERIC;
1054 | else
1055 | ret = i2c_read_blocking_until(i2c_default, addr, &rxdata, 1, false, timeout);
1056 |
1057 | printf(ret < 0 ? "." : "@");
1058 | printf(addr % 16 == 15 ? "\n" : " ");
1059 | }
1060 |
1061 | printf("Done, for real. :-)\n");
1062 |
1063 | uint8_t rxdata, reg;
1064 |
1065 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, &rxdata, 1); printf("b read FUSB_SWITCHES0: %#x ", rxdata); fusb_debug_register(FUSB_SWITCHES0, rxdata); puts(NULL);
1066 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES1, &rxdata, 1); printf("b read FUSB_SWITCHES1: %#x ", rxdata); fusb_debug_register(FUSB_SWITCHES1, rxdata); puts(NULL);
1067 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_MEASURE, &rxdata, 1); printf("b read FUSB_MEASURE: %#x\n", rxdata);
1068 |
1069 | init();
1070 | set_cc(TYPEC_CC_RD); /* swy: this should not be needed, as it's the default; but mark us as the UFP/sink/peripheral device */
1071 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL0, ®); reg |= FUSB_CONTROL0_TX_FLUSH; i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL0, reg);
1072 | /* Flush the RX buffer */
1073 | i2c_read_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL1, ®); reg |= FUSB_CONTROL1_RX_FLUSH; i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL1, reg);
1074 |
1075 | pd_reset();
1076 |
1077 | int cc1_meas, cc2_meas;
1078 | detect_cc_pin_sink(&cc1_meas, &cc2_meas);
1079 |
1080 | /* swy: send a hard reset packet to the other side to restart the PD conversation with anything already plugged-in */
1081 | //i2c_read(i2c_default, FUSB302B_ADDR, FUSB_CONTROL3, ®, 1); reg |= FUSB_CONTROL3_SEND_HARD_RESET;
1082 | //i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL3, reg);
1083 |
1084 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, &rxdata, 1); printf("b read FUSB_SWITCHES0: %#x ", rxdata); fusb_debug_register(FUSB_SWITCHES0, rxdata); puts(NULL);
1085 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES1, &rxdata, 1); printf("b read FUSB_SWITCHES1: %#x ", rxdata); fusb_debug_register(FUSB_SWITCHES1, rxdata); puts(NULL);
1086 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_MEASURE, &rxdata, 1); printf("b read FUSB_MEASURE: %#x\n", rxdata);
1087 |
1088 | uint8_t switchesBackup; i2c_read(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, &switchesBackup, 1); printf("b read FUSB_SWITCHES0: %#x ", switchesBackup); fusb_debug_register(FUSB_SWITCHES0, switchesBackup); puts(NULL);
1089 | uint8_t measureBackup; i2c_read(i2c_default, FUSB302B_ADDR, FUSB_MEASURE, &measureBackup, 1); printf("b read FUSB_MEASURE: %#x\n", measureBackup);
1090 | uint8_t counter = 0, cc1 = 0, cc2 = 0, cc1_is_bigger_than_cc2 = 0; float measured_vbus = 0.f; bool cc_tx_configured = 0;
1091 |
1092 | uint32_t usb_pd_message_header = 0x69;
1093 | uint32_t usb_pd_message_buffer[10] = {0x69}; int ret;
1094 |
1095 | uint8_t buf[32] = {0x69};
1096 |
1097 |
1098 |
1099 | while (1) {
1100 | absolute_time_t from = get_absolute_time();
1101 | if (fusb_interrupt_callback_happened)
1102 | {
1103 | printf("[i] reading interrupt registers\n");
1104 |
1105 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_INTERRUPTA, &dat_int_a, 1); fusb_debug_register(FUSB_INTERRUPTA, dat_int_a);
1106 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_INTERRUPTB, &dat_int_b, 1); fusb_debug_register(FUSB_INTERRUPTB, dat_int_b);
1107 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_INTERRUPT, &dat_int, 1); fusb_debug_register(FUSB_INTERRUPT, dat_int );
1108 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_STATUS1, &dat_stat1, 1); fusb_debug_register(FUSB_STATUS1, dat_stat1 ); puts(NULL);
1109 |
1110 | printf("[i] ---\n");
1111 |
1112 | //if (dat_int & FUSB_INTERRUPT_I_VBUSOK)
1113 | // run_replug = true;
1114 |
1115 | fusb_interrupt_callback_happened = 0;
1116 | }
1117 |
1118 | // 12-bit conversion, assume max value == ADC_VREF == 3.3 V
1119 | const float conversion_factor = 3.3f / (1 << 12);
1120 | //uint16_t result = adc_read();
1121 | //printf("[adc] Raw value: 0x%03x, measured voltage: %f V, actual pre-divided voltage: %f V\n", result, result * conversion_factor, result * (24.f / (1 << 12)));
1122 |
1123 |
1124 |
1125 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_STATUS1, &rxdata, 1); ret = 0;
1126 |
1127 | //if ((rxdata & FUSB_STATUS1_RX_EMPTY) == 0)
1128 | ret = get_message(usb_pd_message_buffer, &usb_pd_message_header);
1129 |
1130 | //if (ret < 0)
1131 | // printf("[!] error in get_message() return=%i", ret);
1132 |
1133 | if((ret > 0))
1134 | {
1135 | printf("[typec] get_message: ret=%i, header=%x, ndataobj=%u, id=%u, pwrole=%u, specrev=%#x, datarole=%u type=%s/%#x buf=",
1136 | ret, usb_pd_message_header, PD_HEADER_CNT(usb_pd_message_header), PD_HEADER_ID(usb_pd_message_header),
1137 | (usb_pd_message_header >> 8) & 0b1,
1138 | (usb_pd_message_header >> 6) & 0b11, /* swy: 0b00 -> 1.0, 0b01 -> 2.0, 0b10 -> 3.0 */
1139 | (usb_pd_message_header >> 5) & 0b1,
1140 | str_pdmsgtype[PD_HEADER_CNT(usb_pd_message_header) > 0][PD_HEADER_TYPE(usb_pd_message_header)], PD_HEADER_TYPE(usb_pd_message_header)
1141 | );
1142 |
1143 | unsigned char *buf = (unsigned char *) &usb_pd_message_buffer[0];
1144 | for (int i = 0, max = (get_num_bytes(usb_pd_message_header) - 2) + 4; i < max; i++)
1145 | printf("%02x %s", buf[i], ((i%4)==3) ? " " : "");
1146 |
1147 | puts(NULL);
1148 |
1149 |
1150 | if (PD_HEADER_CNT(usb_pd_message_header) > 0 && PD_HEADER_TYPE(usb_pd_message_header) == 0x1) /* swy: SOURCE_CAPABILITIES/0x1 */
1151 | {
1152 |
1153 | /* for (int i = 0, max = PD_HEADER_CNT(usb_pd_message_header); i < max; i++)
1154 | {
1155 | uint32_t cur_powerdataobj = (usb_pd_message_buffer[i]); uint32_t cur_powerdataobj_type = (cur_powerdataobj >> 30) & 0b1111;
1156 |
1157 | if (cur_powerdataobj_type == 0b00) printf(" - [%u] Fixed Supply/%#x, Dual Role=%u, USB Suspend=%u, Unconstrained=%u, USB Comms=%u, DualRole=%u, UnchunkedExt=%u, EPR=%u, Peak Current=%u, Voltage=%5umV, Maximum Current=%umA\n", i, cur_powerdataobj_type, ((cur_powerdataobj >> 29) & 0b1), ((cur_powerdataobj >> 28) & 0b1), ((cur_powerdataobj >> 27) & 0b1), ((cur_powerdataobj >> 26) & 0b1), ((cur_powerdataobj >> 25) & 0b1), ((cur_powerdataobj >> 24) & 0b1), ((cur_powerdataobj >> 23) & 0b1), ((cur_powerdataobj >> 20) & 0b11), ((cur_powerdataobj >> 10) & 0b1111111111) * 50, ((cur_powerdataobj >> 0) & 0b1111111111) * 10);
1158 | else if (cur_powerdataobj_type == 0b01) printf(" - [%u] Variable Supply/%#x, Maximum Voltage=%umV, Minimum Voltage=%5umV, Maximum Current=%umA\n", i, cur_powerdataobj_type, ((cur_powerdataobj >> 20) & 0b1111111111) * 50, ((cur_powerdataobj >> 10) & 0b1111111111) * 50, ((cur_powerdataobj >> 0) & 0b1111111111) * 10);
1159 | else if (cur_powerdataobj_type == 0b11) printf(" - [%u] Augmented Power/%#x, Maximum Voltage=%umV, Minimum Voltage=%5umV, Maximum Current=%umA\n", i, cur_powerdataobj_type, ((cur_powerdataobj >> 20) & 0b1111111111) * 50, ((cur_powerdataobj >> 10) & 0b1111111111) * 50, ((cur_powerdataobj >> 0) & 0b1111111111) * 10);
1160 | else printf(" - [%u] FIXME/%#x = %#x %#x\n", i, cur_powerdataobj_type, cur_powerdataobj, usb_pd_message_buffer[i]);
1161 | } */
1162 | }
1163 |
1164 | #define PD_HEADER_SET_CNT(_val) ((_val & 0b111) << 12)
1165 | #define PD_HEADER_SET_ID(_val) ((_val & 0b111) << 9)
1166 | #define PD_HEADER_SPEC_REV(_val) ((_val & 0b11) << 6)
1167 | #define PD_HEADER_SET_TYPE(_val) ((_val & 0b1111) << 0)
1168 |
1169 | absolute_time_t from_send = get_absolute_time();
1170 |
1171 | //send_reset_message();
1172 | ret = send_message(PD_HEADER_SET_CNT(0) | PD_HEADER_SET_ID(PD_HEADER_ID(usb_pd_message_header)) | PD_HEADER_SPEC_REV(2) | PD_HEADER_TYPE(1 /*GOODCRC*/), NULL);
1173 | //printf("send_message() ret=%x\n", ret);
1174 |
1175 | //sleep_us(100);
1176 |
1177 | //ret = send_message(PD_HEADER_SET_CNT(1) | PD_HEADER_SET_ID(0) | PD_HEADER_SPEC_REV(2) | PD_HEADER_TYPE(2 /*REQUEST*/), &(uint32_t) { TU_BSWAP32(0x2CB10411) });
1178 | //printf("send_message() ret=%x\n", ret);
1179 |
1180 | absolute_time_t after = get_absolute_time();
1181 |
1182 | printf("time diff: %llu/%llu %lluus out of 195us\n", from, after, absolute_time_diff_us(from, after));
1183 | printf("time diff: %llu/%llu %lluus out of 195us\n", from_send, after, absolute_time_diff_us(from_send, after));
1184 |
1185 | //sleep_us(100);
1186 |
1187 | //ret = send_message(PD_HEADER_SET_CNT(0) | PD_HEADER_SET_ID(1) | PD_HEADER_SPEC_REV(2) | PD_HEADER_TYPE(7 /*GETSOURCECAP*/), &(uint32_t) { 0 });
1188 | //printf("send_message() ret=%x\n", ret);
1189 |
1190 | }
1191 |
1192 | if (run_replug)
1193 | {
1194 | int cc1_meas_old = cc1_meas,
1195 | cc2_meas_old = cc2_meas;
1196 | detect_cc_pin_sink(&cc1_meas, &cc2_meas);
1197 |
1198 | printf("CC1 level = ");
1199 | switch (cc1_meas) {
1200 | case TYPEC_CC_VOLT_OPEN:
1201 | printf("Open");
1202 | break;
1203 | case TYPEC_CC_VOLT_RA:
1204 | printf("Ra pull-down");
1205 | break;
1206 | case TYPEC_CC_VOLT_RD:
1207 | printf("Rd pull-down");
1208 | break;
1209 | case TYPEC_CC_VOLT_SNK_DEF:
1210 | printf("Connected with default power");
1211 | break;
1212 | case TYPEC_CC_VOLT_SNK_1_5:
1213 | printf("Connected with 1.5A at 5V");
1214 | break;
1215 | case TYPEC_CC_VOLT_SNK_3_0:
1216 | printf("Connected with 3.0A at 5V");
1217 | break;
1218 | default :
1219 | printf("Unknown");
1220 | break;
1221 | }
1222 | puts(NULL);
1223 |
1224 | printf("CC2 level = ");
1225 | switch (cc2_meas) {
1226 | case TYPEC_CC_VOLT_OPEN:
1227 | printf("Open");
1228 | break;
1229 | case TYPEC_CC_VOLT_RA:
1230 | printf("Ra pull-down");
1231 | break;
1232 | case TYPEC_CC_VOLT_RD:
1233 | printf("Rd pull-down");
1234 | break;
1235 | case TYPEC_CC_VOLT_SNK_DEF:
1236 | printf("Connected with default power");
1237 | break;
1238 | case TYPEC_CC_VOLT_SNK_1_5:
1239 | printf("Connected with 1.5A at 5V");
1240 | break;
1241 | case TYPEC_CC_VOLT_SNK_3_0:
1242 | printf("Connected with 3.0A at 5V");
1243 | break;
1244 | default :
1245 | printf("Unknown");
1246 | break;
1247 | }
1248 | puts(NULL);
1249 |
1250 | if(1)//if ((cc1_meas_old > cc2_meas_old) != (cc1_meas > cc2_meas))
1251 | {
1252 | if (cc1_meas > cc2_meas) {
1253 | set_polarity(0); printf("set_polarity(0)\n");
1254 | } else {
1255 | set_polarity(1); printf("set_polarity(1)\n");
1256 | }
1257 | }
1258 | else
1259 | printf("[i] polarity already matches; no changes needed\n");
1260 |
1261 | run_replug = false;
1262 | }
1263 |
1264 |
1265 |
1266 | //measured_vbus = fusb_measure_vbus();
1267 | //cc1_is_bigger_than_cc2 = fusb_compare_cc1_and_cc2();
1268 |
1269 | //printf("[fusb] measured USB-C VBUS: %f, CC1 > CC2: %i\n", measured_vbus, cc1_is_bigger_than_cc2);
1270 |
1271 | if(tud_cdc_available())
1272 | {
1273 | char retrieved_byte = getchar(); printf("serial input: %c\n", retrieved_byte);
1274 |
1275 | if (retrieved_byte > 0)
1276 | {
1277 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_STATUS0, &rxdata, 1); fusb_debug_register(FUSB_STATUS0, rxdata); puts(NULL);
1278 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_STATUS1, &rxdata, 1); fusb_debug_register(FUSB_STATUS1, rxdata); puts(NULL);
1279 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_STATUS0A, &rxdata, 1); fusb_debug_register(FUSB_STATUS0A, rxdata); puts(NULL);
1280 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, &rxdata, 1); fusb_debug_register(FUSB_SWITCHES0, rxdata); puts(NULL);
1281 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES1, &rxdata, 1); fusb_debug_register(FUSB_SWITCHES1, rxdata); puts(NULL);
1282 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_POWER, &rxdata, 1); fusb_debug_register(FUSB_POWER, rxdata); puts(NULL);
1283 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_CONTROL0, &rxdata, 1); fusb_debug_register(FUSB_CONTROL0, rxdata); puts(NULL);
1284 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_CONTROL1, &rxdata, 1); fusb_debug_register(FUSB_CONTROL1, rxdata); puts(NULL);
1285 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_CONTROL2, &rxdata, 1); fusb_debug_register(FUSB_CONTROL2, rxdata); puts(NULL);
1286 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_CONTROL3, &rxdata, 1); fusb_debug_register(FUSB_CONTROL3, rxdata); puts(NULL);
1287 | printf("--\n");
1288 | run_replug = true;
1289 |
1290 | if (retrieved_byte == 'r')
1291 | {
1292 | /* swy: send a hard reset packet to the other side to restart the PD conversation with anything already plugged-in */
1293 | //i2c_read(i2c_default, FUSB302B_ADDR, FUSB_CONTROL3, ®, 1); reg |= FUSB_CONTROL3_SEND_HARD_RESET; i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL3, reg);
1294 | set_cc(TYPEC_CC_OPEN);
1295 | sleep_ms(1500);
1296 | init();
1297 | set_cc(TYPEC_CC_RD); /* swy: this should not be needed, as it's the default; but mark us as the UFP/sink/peripheral device */
1298 | //i2c_read(i2c_default, FUSB302B_ADDR, FUSB_CONTROL3, ®, 1); reg |= FUSB_CONTROL3_SEND_HARD_RESET; i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL3, reg);
1299 | /* Flush the RX buffer */
1300 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH);
1301 | pd_reset();
1302 | }
1303 | }
1304 | }
1305 |
1306 | if (0) //(!cc_tx_configured)//measured_vbus > 3 && !cc_tx_configured)
1307 | {
1308 | uint8_t reg; i2c_read(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, ®, 1); fusb_debug_register(FUSB_SWITCHES0, reg); puts(NULL);
1309 | /* Clear CC1/CC2 measure bits */
1310 | reg &= ~FUSB_SWITCHES0_MEAS_CC1;
1311 | reg &= ~FUSB_SWITCHES0_MEAS_CC2;
1312 |
1313 | if (1) reg |= FUSB_SWITCHES0_MEAS_CC1;
1314 | else reg |= FUSB_SWITCHES0_MEAS_CC2;
1315 |
1316 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES0, reg); printf("cc1_is_bigger_than_cc2 cc1 write FUSB_SWITCHES1:"); fusb_debug_register(FUSB_SWITCHES1, reg); puts(NULL);
1317 |
1318 | i2c_read(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES1, ®, 1);
1319 | reg |= FUSB_SWITCHES1_AUTO_CRC;
1320 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_SWITCHES1, reg); printf("cc1_is_bigger_than_cc2 cc1 write FUSB_SWITCHES1:"); fusb_debug_register(FUSB_SWITCHES1, reg); puts(NULL);
1321 |
1322 | /* Flush the RX buffer */
1323 | i2c_write_byte(i2c_default, FUSB302B_ADDR, FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH); printf("f write FUSB_CONTROL1:\n");
1324 | cc_tx_configured = 1;
1325 | }
1326 |
1327 |
1328 | //gpio_put(PSDAPT_PIN_HMD_ENABLE_VBUS, 0);
1329 | //gpio_put(PSDAPT_PIN_HMD_ENABLE_VBUS_12V, 0);
1330 |
1331 | //sleep_ms(500);
1332 |
1333 |
1334 | #if 0//ndef PICO_DEFAULT_LED_PIN
1335 | #warning blink example requires a board with a regular LED
1336 | #else
1337 | //gpio_put(PSDAPT_PIN_LED_CONN_WRONG_ORIENT, 1); //(measured_vbus > 0.f && cc1_is_bigger_than_cc2) ? 1 : 0);
1338 |
1339 | // gpio_put(PSDAPT_PIN_LED_HMD_IS_READY, 0);
1340 | // sleep_ms(250);
1341 | // gpio_put(PSDAPT_PIN_PC_HPD, 1);
1342 | // sleep_ms(2);
1343 | // gpio_put(PSDAPT_PIN_PC_HPD, 0);
1344 | // sleep_ms(250);
1345 | // gpio_put(PSDAPT_PIN_LED_CONN_WRONG_ORIENT, 0);
1346 | // gpio_put(PSDAPT_PIN_LED_HMD_IS_READY, measured_vbus > 0.f ? 1 : 0);
1347 | // sleep_ms(250);
1348 | // gpio_put(PSDAPT_PIN_PC_HPD, 0);
1349 | #endif
1350 |
1351 | }
1352 | }
1353 |
--------------------------------------------------------------------------------