|
|
@ -1,32 +1,25 @@ |
|
|
|
/*
|
|
|
|
/* Copyright 2021 QMK
|
|
|
|
Copyright 2018 Massdrop Inc. |
|
|
|
* |
|
|
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
|
|
This program is free software: you can redistribute it and/or modify |
|
|
|
* it under the terms of the GNU General Public License as published by |
|
|
|
it under the terms of the GNU General Public License as published by |
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
|
|
the Free Software Foundation, either version 2 of the License, or |
|
|
|
* (at your option) any later version. |
|
|
|
(at your option) any later version. |
|
|
|
* |
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful, |
|
|
|
This program is distributed in the hope that it will be useful, |
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
* GNU General Public License for more details. |
|
|
|
GNU General Public License for more details. |
|
|
|
* |
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License |
|
|
|
You should have received a copy of the GNU General Public License |
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
#include <string.h> |
|
|
|
#ifndef _USB2422_H_ |
|
|
|
#include "usb2422.h" |
|
|
|
#define _USB2422_H_ |
|
|
|
#include "i2c_master.h" |
|
|
|
|
|
|
|
#include "wait.h" |
|
|
|
#define REV_USB2422 0x100 |
|
|
|
#include "gpio.h" |
|
|
|
|
|
|
|
|
|
|
|
#define USB2422_ADDR 0x58 // I2C device address, one instance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define USB2422_HUB_ACTIVE_GROUP 0 // PA
|
|
|
|
|
|
|
|
#define USB2422_HUB_ACTIVE_PIN 18 // 18
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_VID : (USB2422L Offset: 0x00) (R/W 16) Vendor ID -------- */ |
|
|
|
/* -------- USB2422_VID : (USB2422L Offset: 0x00) (R/W 16) Vendor ID -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint16_t VID_LSB : 8; |
|
|
|
uint16_t VID_LSB : 8; |
|
|
@ -34,10 +27,8 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint16_t reg; /*!< Type used for register access */ |
|
|
|
uint16_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_VID_Type; |
|
|
|
} USB2422_VID_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_PID : (USB2422L Offset: 0x02) (R/W 16) Product ID -------- */ |
|
|
|
/* -------- USB2422_PID : (USB2422L Offset: 0x02) (R/W 16) Product ID -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint16_t PID_LSB : 8; |
|
|
|
uint16_t PID_LSB : 8; |
|
|
@ -45,10 +36,8 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint16_t reg; /*!< Type used for register access */ |
|
|
|
uint16_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_PID_Type; |
|
|
|
} USB2422_PID_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_DID : (USB2422L Offset: 0x04) (R/W 16) Device ID -------- */ |
|
|
|
/* -------- USB2422_DID : (USB2422L Offset: 0x04) (R/W 16) Device ID -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint16_t DID_LSB : 8; |
|
|
|
uint16_t DID_LSB : 8; |
|
|
@ -56,10 +45,8 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint16_t reg; /*!< Type used for register access */ |
|
|
|
uint16_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_DID_Type; |
|
|
|
} USB2422_DID_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_CFG1 : (USB2422L Offset: 0x06) (R/W 8) Configuration Data Byte 1-------- */ |
|
|
|
/* -------- USB2422_CFG1 : (USB2422L Offset: 0x06) (R/W 8) Configuration Data Byte 1-------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t PORT_PWR : 1; |
|
|
|
uint8_t PORT_PWR : 1; |
|
|
@ -72,10 +59,8 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_CFG1_Type; |
|
|
|
} USB2422_CFG1_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_CFG2 : (USB2422L Offset: 0x07) (R/W 8) Configuration Data Byte 2-------- */ |
|
|
|
/* -------- USB2422_CFG2 : (USB2422L Offset: 0x07) (R/W 8) Configuration Data Byte 2-------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t : 3; |
|
|
|
uint8_t : 3; |
|
|
@ -86,10 +71,8 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_CFG2_Type; |
|
|
|
} USB2422_CFG2_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_CFG3 : (USB2422L Offset: 0x08) (R/W 16) Configuration Data Byte 3-------- */ |
|
|
|
/* -------- USB2422_CFG3 : (USB2422L Offset: 0x08) (R/W 16) Configuration Data Byte 3-------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t STRING_EN : 1; |
|
|
|
uint8_t STRING_EN : 1; |
|
|
@ -99,10 +82,8 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_CFG3_Type; |
|
|
|
} USB2422_CFG3_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_NRD : (USB2422L Offset: 0x09) (R/W 8) Non Removable Device -------- */ |
|
|
|
/* -------- USB2422_NRD : (USB2422L Offset: 0x09) (R/W 8) Non Removable Device -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t : 5; |
|
|
|
uint8_t : 5; |
|
|
@ -112,10 +93,8 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_NRD_Type; |
|
|
|
} USB2422_NRD_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_PDS : (USB2422L Offset: 0x0A) (R/W 8) Port Diable for Self-Powered Operation -------- */ |
|
|
|
/* -------- USB2422_PDS : (USB2422L Offset: 0x0A) (R/W 8) Port Diable for Self-Powered Operation -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t : 1; |
|
|
|
uint8_t : 1; |
|
|
@ -125,10 +104,9 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_PDS_Type; |
|
|
|
} USB2422_PDS_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_PDB : (USB2422L Offset: 0x0B) (R/W 8) Port Diable for Bus-Powered Operation -------- */ |
|
|
|
/* -------- USB2422_PDB : (USB2422L Offset: 0x0B) (R/W 8) Port Diable for Bus-Powered Operation -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t : 1; |
|
|
|
uint8_t : 1; |
|
|
@ -138,125 +116,98 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_PDB_Type; |
|
|
|
} USB2422_PDB_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_MAXPS : (USB2422L Offset: 0x0C) (R/W 8) Max Power for Self-Powered Operation -------- */ |
|
|
|
/* -------- USB2422_MAXPS : (USB2422L Offset: 0x0C) (R/W 8) Max Power for Self-Powered Operation -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t MAX_PWR_SP : 8; |
|
|
|
uint8_t MAX_PWR_SP : 8; |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_MAXPS_Type; |
|
|
|
} USB2422_MAXPS_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_MAXPB : (USB2422L Offset: 0x0D) (R/W 8) Max Power for Bus-Powered Operation -------- */ |
|
|
|
/* -------- USB2422_MAXPB : (USB2422L Offset: 0x0D) (R/W 8) Max Power for Bus-Powered Operation -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t MAX_PWR_BP : 8; |
|
|
|
uint8_t MAX_PWR_BP : 8; |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_MAXPB_Type; |
|
|
|
} USB2422_MAXPB_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_HCMCS : (USB2422L Offset: 0x0E) (R/W 8) Hub Controller Max Current for Self-Powered Operation -------- */ |
|
|
|
/* -------- USB2422_HCMCS : (USB2422L Offset: 0x0E) (R/W 8) Hub Controller Max Current for Self-Powered Operation -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t HC_MAX_C_SP : 8; |
|
|
|
uint8_t HC_MAX_C_SP : 8; |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_HCMCS_Type; |
|
|
|
} USB2422_HCMCS_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_HCMCB : (USB2422L Offset: 0x0F) (R/W 8) Hub Controller Max Current for Bus-Powered Operation -------- */ |
|
|
|
/* -------- USB2422_HCMCB : (USB2422L Offset: 0x0F) (R/W 8) Hub Controller Max Current for Bus-Powered Operation -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t HC_MAX_C_BP : 8; |
|
|
|
uint8_t HC_MAX_C_BP : 8; |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_HCMCB_Type; |
|
|
|
} USB2422_HCMCB_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_PWRT : (USB2422L Offset: 0x10) (R/W 8) Power On Time -------- */ |
|
|
|
/* -------- USB2422_PWRT : (USB2422L Offset: 0x10) (R/W 8) Power On Time -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t POWER_ON_TIME : 8; |
|
|
|
uint8_t POWER_ON_TIME : 8; |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_PWRT_Type; |
|
|
|
} USB2422_PWRT_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_LANGID LSB : (USB2422L Offset: 0x11) (R/W 16) Language ID -------- */ |
|
|
|
/* -------- USB2422_LANGID LSB : (USB2422L Offset: 0x11) (R/W 16) Language ID -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t LANGID_LSB : 8; |
|
|
|
uint8_t LANGID_LSB : 8; |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_LANGID_LSB_Type; |
|
|
|
} USB2422_LANGID_LSB_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_LANGID MSB : (USB2422L Offset: 0x12) (R/W 16) Language ID -------- */ |
|
|
|
/* -------- USB2422_LANGID MSB : (USB2422L Offset: 0x12) (R/W 16) Language ID -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t LANGID_MSB : 8; |
|
|
|
uint8_t LANGID_MSB : 8; |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_LANGID_MSB_Type; |
|
|
|
} USB2422_LANGID_MSB_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_MFRSL : (USB2422L Offset: 0x13) (R/W 8) Manufacturer String Length -------- */ |
|
|
|
/* -------- USB2422_MFRSL : (USB2422L Offset: 0x13) (R/W 8) Manufacturer String Length -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t MFR_STR_LEN : 8; |
|
|
|
uint8_t MFR_STR_LEN : 8; |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_MFRSL_Type; |
|
|
|
} USB2422_MFRSL_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_PRDSL : (USB2422L Offset: 0x14) (R/W 8) Product String Length -------- */ |
|
|
|
/* -------- USB2422_PRDSL : (USB2422L Offset: 0x14) (R/W 8) Product String Length -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t PRD_STR_LEN : 8; |
|
|
|
uint8_t PRD_STR_LEN : 8; |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_PRDSL_Type; |
|
|
|
} USB2422_PRDSL_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_SERSL : (USB2422L Offset: 0x15) (R/W 8) Serial String Length -------- */ |
|
|
|
/* -------- USB2422_SERSL : (USB2422L Offset: 0x15) (R/W 8) Serial String Length -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t SER_STR_LEN : 8; |
|
|
|
uint8_t SER_STR_LEN : 8; |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_SERSL_Type; |
|
|
|
} USB2422_SERSL_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_MFRSTR : (USB2422L Offset: 0x16-53) (R/W 8) Maufacturer String -------- */ |
|
|
|
/* -------- USB2422_MFRSTR : (USB2422L Offset: 0x16-53) (R/W 8) Maufacturer String -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef uint16_t USB2422_MFRSTR_Type; |
|
|
|
typedef uint16_t USB2422_MFRSTR_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_PRDSTR : (USB2422L Offset: 0x54-91) (R/W 8) Product String -------- */ |
|
|
|
/* -------- USB2422_PRDSTR : (USB2422L Offset: 0x54-91) (R/W 8) Product String -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef uint16_t USB2422_PRDSTR_Type; |
|
|
|
typedef uint16_t USB2422_PRDSTR_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_SERSTR : (USB2422L Offset: 0x92-CF) (R/W 8) Serial String -------- */ |
|
|
|
/* -------- USB2422_SERSTR : (USB2422L Offset: 0x92-CF) (R/W 8) Serial String -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef uint16_t USB2422_SERSTR_Type; |
|
|
|
typedef uint16_t USB2422_SERSTR_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_BCEN : (USB2422L Offset: 0xD0) (R/W 8) Battery Charging Enable -------- */ |
|
|
|
/* -------- USB2422_BCEN : (USB2422L Offset: 0xD0) (R/W 8) Battery Charging Enable -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t : 1; |
|
|
|
uint8_t : 1; |
|
|
@ -266,10 +217,8 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_BCEN_Type; |
|
|
|
} USB2422_BCEN_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_BOOSTUP : (USB2422L Offset: 0xF6) (R/W 8) Boost Upstream -------- */ |
|
|
|
/* -------- USB2422_BOOSTUP : (USB2422L Offset: 0xF6) (R/W 8) Boost Upstream -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t BOOST : 2; |
|
|
|
uint8_t BOOST : 2; |
|
|
@ -277,10 +226,8 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_BOOSTUP_Type; |
|
|
|
} USB2422_BOOSTUP_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_BOOSTDOWN : (USB2422L Offset: 0xF8) (R/W 8) Boost Downstream -------- */ |
|
|
|
/* -------- USB2422_BOOSTDOWN : (USB2422L Offset: 0xF8) (R/W 8) Boost Downstream -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t BOOST1 : 2; |
|
|
|
uint8_t BOOST1 : 2; |
|
|
@ -289,10 +236,8 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_BOOSTDOWN_Type; |
|
|
|
} USB2422_BOOSTDOWN_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_PRTSP : (USB2422L Offset: 0xFA) (R/W 8) Port Swap -------- */ |
|
|
|
/* -------- USB2422_PRTSP : (USB2422L Offset: 0xFA) (R/W 8) Port Swap -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t : 1; |
|
|
|
uint8_t : 1; |
|
|
@ -302,10 +247,8 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_PRTSP_Type; |
|
|
|
} USB2422_PRTSP_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_PRTR12 : (USB2422L Offset: 0xFB) (R/W 8) Port 1/2 Remap -------- */ |
|
|
|
/* -------- USB2422_PRTR12 : (USB2422L Offset: 0xFB) (R/W 8) Port 1/2 Remap -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t PORT1_REMAP : 4; |
|
|
|
uint8_t PORT1_REMAP : 4; |
|
|
@ -313,7 +256,7 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_PRTR12_Type; |
|
|
|
} USB2422_PRTR12_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
#define USB2422_PRTR12_DISABLE 0 |
|
|
|
#define USB2422_PRTR12_DISABLE 0 |
|
|
|
#define USB2422_PRT12_P2TOL1 1 |
|
|
|
#define USB2422_PRT12_P2TOL1 1 |
|
|
|
#define USB2422_PRT12_P2XTOL2 2 |
|
|
|
#define USB2422_PRT12_P2XTOL2 2 |
|
|
@ -321,7 +264,6 @@ typedef union { |
|
|
|
#define USB2422_PRT12_P1XTOL2 2 |
|
|
|
#define USB2422_PRT12_P1XTOL2 2 |
|
|
|
|
|
|
|
|
|
|
|
/* -------- USB2422_STCD : (USB2422L Offset: 0xFF) (R/W 8) Status Command -------- */ |
|
|
|
/* -------- USB2422_STCD : (USB2422L Offset: 0xFF) (R/W 8) Status Command -------- */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef union { |
|
|
|
typedef union { |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
uint8_t USB_ATTACH : 1; |
|
|
|
uint8_t USB_ATTACH : 1; |
|
|
@ -331,10 +273,8 @@ typedef union { |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
} bit; /*!< Structure used for bit access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
uint8_t reg; /*!< Type used for register access */ |
|
|
|
} USB2422_STCD_Type; |
|
|
|
} USB2422_STCD_Type; |
|
|
|
#endif /* !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief USB2422 device hardware registers */ |
|
|
|
/** \brief USB2422 device hardware registers */ |
|
|
|
#if !(defined(__ASSEMBLY__) || defined(__IAR_SYSTEMS_ASM__)) |
|
|
|
|
|
|
|
typedef struct { |
|
|
|
typedef struct { |
|
|
|
USB2422_VID_Type VID; /**< \brief Offset: 0x00*/ |
|
|
|
USB2422_VID_Type VID; /**< \brief Offset: 0x00*/ |
|
|
|
USB2422_PID_Type PID; /**< \brief Offset: 0x02*/ |
|
|
|
USB2422_PID_Type PID; /**< \brief Offset: 0x02*/ |
|
|
@ -368,35 +308,95 @@ typedef struct { |
|
|
|
USB2422_PRTR12_Type PRTR12; /**< \brief Offset: 0xFB*/ |
|
|
|
USB2422_PRTR12_Type PRTR12; /**< \brief Offset: 0xFB*/ |
|
|
|
uint8_t Reserved4[0x3]; |
|
|
|
uint8_t Reserved4[0x3]; |
|
|
|
USB2422_STCD_Type STCD; /**< \brief Offset: 0xFF*/ |
|
|
|
USB2422_STCD_Type STCD; /**< \brief Offset: 0xFF*/ |
|
|
|
} Usb2422; |
|
|
|
} Usb2422_t; |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define PORT_DETECT_RETRY_INTERVAL 2000 |
|
|
|
// ***************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
#define USB_EXTRA_ADC_THRESHOLD 900 |
|
|
|
static Usb2422_t config; |
|
|
|
|
|
|
|
|
|
|
|
#define USB_EXTRA_STATE_DISABLED 0 |
|
|
|
// ***************************************************************
|
|
|
|
#define USB_EXTRA_STATE_ENABLED 1 |
|
|
|
|
|
|
|
#define USB_EXTRA_STATE_UNKNOWN 2 |
|
|
|
|
|
|
|
#define USB_EXTRA_STATE_DISABLED_UNTIL_REPLUG 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define USB_HOST_PORT_1 0 |
|
|
|
/** \brief Handle the conversion to allow simple strings
|
|
|
|
#define USB_HOST_PORT_2 1 |
|
|
|
*/ |
|
|
|
#define USB_HOST_PORT_UNKNOWN 2 |
|
|
|
static void USB2422_strcpy(const char* str, USB2422_MFRSTR_Type* dest, uint8_t len) { |
|
|
|
|
|
|
|
for (uint8_t i = 0; i < len; i++) { |
|
|
|
|
|
|
|
dest[i] = str[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
extern uint8_t usb_host_port; |
|
|
|
/** \brief Handle the conversion to allow simple strings
|
|
|
|
extern uint8_t usb_extra_state; |
|
|
|
*/ |
|
|
|
extern uint8_t usb_extra_manual; |
|
|
|
static void USB2422_write_block(void) { |
|
|
|
extern uint8_t usb_gcr_auto; |
|
|
|
static unsigned char i2c0_buf[34]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned char* dest = i2c0_buf; |
|
|
|
|
|
|
|
unsigned char* src; |
|
|
|
|
|
|
|
unsigned char* base = (unsigned char*)&config; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (src = base; src < base + 256; src += 32) { |
|
|
|
|
|
|
|
dest[0] = src - base; |
|
|
|
|
|
|
|
dest[1] = 32; |
|
|
|
|
|
|
|
memcpy(&dest[2], src, 32); |
|
|
|
|
|
|
|
i2c_transmit(USB2422_ADDRESS, dest, 34, 50000); |
|
|
|
|
|
|
|
wait_us(100); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void USB2422_init() { |
|
|
|
|
|
|
|
#ifdef USB2422_RESET_PIN |
|
|
|
|
|
|
|
setPinOutput(USB2422_RESET_PIN); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
#ifdef USB2422_ACTIVE_PIN |
|
|
|
|
|
|
|
setPinInput(USB2422_ACTIVE_PIN); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
void USB2422_init(void); |
|
|
|
i2c_init(); // IC2 clk must be high at USB2422 reset release time to signal SMB configuration
|
|
|
|
void USB_reset(void); |
|
|
|
} |
|
|
|
void USB_configure(void); |
|
|
|
|
|
|
|
uint16_t USB_active(void); |
|
|
|
void USB2422_configure() { |
|
|
|
void USB_set_host_by_voltage(void); |
|
|
|
static const char SERNAME[] = "Unavailable"; |
|
|
|
uint16_t adc_get(uint8_t muxpos); |
|
|
|
|
|
|
|
uint8_t USB2422_Port_Detect_Init(void); |
|
|
|
memset(&config, 0, sizeof(Usb2422_t)); |
|
|
|
void USB_HandleExtraDevice(void); |
|
|
|
|
|
|
|
void USB_ExtraSetState(uint8_t state); |
|
|
|
// configure Usb2422 registers
|
|
|
|
|
|
|
|
config.VID.reg = USB2422_VENDOR_ID; |
|
|
|
|
|
|
|
config.PID.reg = USB2422_PRODUCT_ID; |
|
|
|
|
|
|
|
config.DID.reg = USB2422_DEVICE_VER; // BCD format, eg 01.01
|
|
|
|
|
|
|
|
config.CFG1.bit.SELF_BUS_PWR = 1; // self powered for now
|
|
|
|
|
|
|
|
config.CFG1.bit.HS_DISABLE = 1; // full or high speed
|
|
|
|
|
|
|
|
// config.CFG2.bit.COMPOUND = 0; // compound device
|
|
|
|
|
|
|
|
config.CFG3.bit.STRING_EN = 1; // strings enabled
|
|
|
|
|
|
|
|
// config.NRD.bit.PORT2_NR = 0; // MCU is non-removable
|
|
|
|
|
|
|
|
config.MAXPB.reg = 20; // 0mA
|
|
|
|
|
|
|
|
config.HCMCB.reg = 20; // 0mA
|
|
|
|
|
|
|
|
config.MFRSL.reg = sizeof(USB2422_MANUFACTURER); |
|
|
|
|
|
|
|
config.PRDSL.reg = sizeof(USB2422_PRODUCT); |
|
|
|
|
|
|
|
config.SERSL.reg = sizeof(SERNAME); |
|
|
|
|
|
|
|
USB2422_strcpy(USB2422_MANUFACTURER, config.MFRSTR, sizeof(USB2422_MANUFACTURER)); |
|
|
|
|
|
|
|
USB2422_strcpy(USB2422_PRODUCT, config.PRDSTR, sizeof(USB2422_PRODUCT)); |
|
|
|
|
|
|
|
USB2422_strcpy(SERNAME, config.SERSTR, sizeof(SERNAME)); |
|
|
|
|
|
|
|
// config.BOOSTUP.bit.BOOST=3; //upstream port
|
|
|
|
|
|
|
|
// config.BOOSTDOWN.bit.BOOST1=0; // extra port
|
|
|
|
|
|
|
|
// config.BOOSTDOWN.bit.BOOST2=2; //MCU is close
|
|
|
|
|
|
|
|
config.STCD.bit.USB_ATTACH = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
USB2422_write_block(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void USB2422_reset() { |
|
|
|
|
|
|
|
#ifdef USB2422_RESET_PIN |
|
|
|
|
|
|
|
writePinLow(USB2422_RESET_PIN); |
|
|
|
|
|
|
|
wait_us(2); |
|
|
|
|
|
|
|
writePinHigh(USB2422_RESET_PIN); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif //_USB2422_H_
|
|
|
|
bool USB2422_active() { |
|
|
|
|
|
|
|
#ifdef USB2422_ACTIVE_PIN |
|
|
|
|
|
|
|
return readPin(USB2422_ACTIVE_PIN); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
} |