From d1eb78aa9eac52f4e34c15bde9b090d8029578c8 Mon Sep 17 00:00:00 2001 From: Wenting Zhang Date: Sat, 22 Jun 2024 17:19:37 -0700 Subject: [PATCH] Back port to r0p6 --- fw/button.c | 7 +++++++ fw/config.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++-- fw/fpga.c | 9 +------- fw/fw.c | 10 ++++----- fw/ptn3460.c | 4 ---- fw/tcpm_driver.c | 3 +-- fw/usb_mux.c | 6 ++---- 7 files changed, 68 insertions(+), 25 deletions(-) diff --git a/fw/button.c b/fw/button.c index 7e1b83e..745be96 100644 --- a/fw/button.c +++ b/fw/button.c @@ -21,6 +21,7 @@ // #include #include "pico/stdlib.h" +#include "config.h" #include "button.h" #define BTN1 6 @@ -33,6 +34,7 @@ #define RELEASE_THRESHOLD 20 void button_init() { +#ifdef HAS_BUTTON gpio_init(BTN1); gpio_set_dir(BTN1, GPIO_IN); gpio_pull_up(BTN1); @@ -40,6 +42,7 @@ void button_init() { gpio_init(BTN2); gpio_set_dir(BTN2, GPIO_IN); gpio_pull_up(BTN2); +#endif } // Scan a single key, ID is the key number from 0, gpio is pin number @@ -119,8 +122,12 @@ static uint32_t button_scan_single(int id, int gpio) { } uint32_t button_scan() { +#ifdef HAS_BUTTON uint32_t btn1 = button_scan_single(0, BTN1); uint32_t btn2 = button_scan_single(1, BTN2); uint32_t retval = (btn1 & 0x3) | ((btn2 & 0x3) << 2); return retval; +#else + return 0; +#endif } diff --git a/fw/config.h b/fw/config.h index f7eaf44..de6405f 100644 --- a/fw/config.h +++ b/fw/config.h @@ -23,7 +23,8 @@ /* BOARD REVISION CONFIGURATION */ // Eariler revisions are not supported -#define BOARD_REV_R0P7 +#define BOARD_REV_R0P6 +//#define BOARD_REV_R0P7 /* SCREEN CONFIGURATION */ @@ -53,12 +54,61 @@ /* SET BASED ON PREVIOUS DEFINES, DO NOT MODIFY */ -#if defined(BOARD_REV_R0P7) +#if defined(BOARD_REV_R0P6) +#define POWER_GPIO +#define INPUT_PTN3460 +#define HAS_TYPEC + +#define TYPEC_MB_ORI_INV 1 +#define TYPEC_AUX_ORI_INV 1 + +#define I2C_SDA 0 +#define I2C_SCL 1 + +#define TCPC_I2C i2c0 + +#define FPGA_CS 12 +#define FPGA_MOSI 13 +#define FPGA_MISO 14 +#define FPGA_SCLK 15 +#define FPGA_PROG 17 +#define FPGA_DONE 18 +#define FPGA_SUSP 19 + +#define PTN3460_I2C (i2c0) +#define PTN3460_HPD_PIN (8) +#define PTN3460_PDN_PIN (9) +#define PTN3460_VALID_PIN (2) + +#elif defined(BOARD_REV_R0P7) #define POWER_GPIO #define POWER_GPIO_VCOM_MEASURE #define INPUT_ADV7611 #define INPUT_PTN3460 #define HAS_TYPEC +#define HAS_BUTTON + +#define TYPEC_MB_ORI_INV 0 +#define TYPEC_AUX_ORI_INV 1 + +#define I2C_SDA 2 +#define I2C_SCL 3 + +#define TCPC_I2C i2c1 + +#define FPGA_CS 13 +#define FPGA_MOSI 15 +#define FPGA_MISO 12 +#define FPGA_SCLK 14 +#define FPGA_PROG 17 +#define FPGA_DONE 18 +#define FPGA_SUSP 19 + +#define PTN3460_I2C (i2c1) +#define PTN3460_HPD_PIN (7) +#define PTN3460_PDN_PIN (9) +#define PTN3460_VALID_PIN (4) + #else #error "Unknown board revision" #endif diff --git a/fw/fpga.c b/fw/fpga.c index 8bc7cb1..447a1b5 100644 --- a/fw/fpga.c +++ b/fw/fpga.c @@ -22,17 +22,10 @@ #include "pico/stdlib.h" #include #include "utils.h" +#include "config.h" #include "fpga.h" #include "bitstream.h" -#define FPGA_CS 13 -#define FPGA_MOSI 15 -#define FPGA_MISO 12 -#define FPGA_SCLK 14 -#define FPGA_PROG 17 -#define FPGA_DONE 18 -#define FPGA_SUSP 19 - static int fpga_done = 0; static void gpio_init_out(uint32_t pin, bool val) { diff --git a/fw/fw.c b/fw/fw.c index 06d7838..2867a15 100644 --- a/fw/fw.c +++ b/fw/fw.c @@ -51,11 +51,11 @@ int main() #endif // Initialize I2C for TCPC/PTN3460/ADV7611 use - i2c_init(i2c1, 100*1000); - gpio_set_function(2, GPIO_FUNC_I2C); - gpio_set_function(3, GPIO_FUNC_I2C); - gpio_pull_up(2); - gpio_pull_up(3); + i2c_init(TCPC_I2C, 100*1000); + gpio_set_function(I2C_SDA, GPIO_FUNC_I2C); + gpio_set_function(I2C_SCL, GPIO_FUNC_I2C); + gpio_pull_up(I2C_SDA); + gpio_pull_up(I2C_SCL); #ifdef HAS_TYPEC int result = tcpm_init(0); diff --git a/fw/ptn3460.c b/fw/ptn3460.c index c43c0ab..c1070db 100644 --- a/fw/ptn3460.c +++ b/fw/ptn3460.c @@ -31,10 +31,6 @@ #ifdef INPUT_PTN3460 #define PTN3460_I2C_ADDRESS (0x60) -#define PTN3460_I2C (i2c1) -#define PTN3460_HPD_PIN (7) -#define PTN3460_PDN_PIN (9) -#define PTN3460_VALID_PIN (4) void ptn3460_select_edid_emulation(uint8_t id) { uint8_t buf[2]; diff --git a/fw/tcpm_driver.c b/fw/tcpm_driver.c index cd06397..f86434a 100644 --- a/fw/tcpm_driver.c +++ b/fw/tcpm_driver.c @@ -20,6 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // +#include "config.h" #include "tcpm_driver.h" #include "pico/stdlib.h" #include "hardware/i2c.h" @@ -29,8 +30,6 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { {0, FUSB302_I2C_SLAVE_ADDR, &fusb302_tcpm_drv}, }; -#define TCPC_I2C i2c1 - void tcpc_i2c_init(void) { // Should be initialized at board level init to avoid dependencies between // drivers that need I2C diff --git a/fw/usb_mux.c b/fw/usb_mux.c index d58eb95..264b5a5 100644 --- a/fw/usb_mux.c +++ b/fw/usb_mux.c @@ -48,15 +48,13 @@ void usb_mux_set(int port, enum typec_mux mux_mode, if (polarity == 0) { // Not flipped printf("Setting orientation to not flipped\n"); - gpio_put(USBC_ORI_PIN, 0); - ptn3460_set_aux_polarity(1); } else { // Flipped printf("Setting orientation to flipped\n"); - gpio_put(USBC_ORI_PIN, 1); - ptn3460_set_aux_polarity(0); } + gpio_put(USBC_ORI_PIN, polarity ^ TYPEC_MB_ORI_INV); + ptn3460_set_aux_polarity(polarity ^ TYPEC_AUX_ORI_INV); } }