spi.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. Copyright 2018 Massdrop Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef _SPI_H_
  15. #define _SPI_H_
  16. /* Macros for Shift Register control */
  17. #define SR_EXP_RCLK_LO PORT->Group[SR_EXP_RCLK_PORT].OUTCLR.reg = (1 << SR_EXP_RCLK_PIN)
  18. #define SR_EXP_RCLK_HI PORT->Group[SR_EXP_RCLK_PORT].OUTSET.reg = (1 << SR_EXP_RCLK_PIN)
  19. #define SR_EXP_OE_N_ENA PORT->Group[SR_EXP_OE_N_PORT].OUTCLR.reg = (1 << SR_EXP_OE_N_PIN)
  20. #define SR_EXP_OE_N_DIS PORT->Group[SR_EXP_OE_N_PORT].OUTSET.reg = (1 << SR_EXP_OE_N_PIN)
  21. /* Determine bits to set for mux selection */
  22. #if SR_EXP_DATAOUT_PIN % 2 == 0
  23. #define SR_EXP_DATAOUT_MUX_SEL PMUXE
  24. #else
  25. #define SR_EXP_DATAOUT_MUX_SEL PMUXO
  26. #endif
  27. /* Determine bits to set for mux selection */
  28. #if SR_EXP_SCLK_PIN % 2 == 0
  29. #define SR_EXP_SCLK_MUX_SEL PMUXE
  30. #else
  31. #define SR_EXP_SCLK_MUX_SEL PMUXO
  32. #endif
  33. /* Data structure to define Shift Register output expander hardware */
  34. /* This structure gets shifted into registers LSB first */
  35. typedef union {
  36. struct {
  37. uint16_t RSVD4:1; /*!< bit: 0 */
  38. uint16_t RSVD3:1; /*!< bit: 1 */
  39. uint16_t RSVD2:1; /*!< bit: 2 */
  40. uint16_t RSVD1:1; /*!< bit: 3 */
  41. uint16_t SDB_N:1; /*!< bit: 4 SHUTDOWN THE CHIP WHEN 0, RUN WHEN 1 */
  42. uint16_t IRST:1; /*!< bit: 5 RESET THE IS3733 I2C WHEN 1, RUN WHEN 0 */
  43. uint16_t SRC_2:1; /*!< bit: 6 ADVERTISE A SOURCE TO USBC-2 CC */
  44. uint16_t SRC_1:1; /*!< bit: 7 ADVERTISE A SOURCE TO USBC-1 CC */
  45. uint16_t E_VBUS_2:1; /*!< bit: 8 ENABLE 5V OUT TO USBC-2 WHEN 1 */
  46. uint16_t E_VBUS_1:1; /*!< bit: 9 ENABLE 5V OUT TO USBC-1 WHEN 1 */
  47. uint16_t E_DN1_N:1; /*!< bit: 10 ENABLE DN1 1:2 MUX WHEN 0 */
  48. uint16_t S_DN1:1; /*!< bit: 11 SELECT DN1 PATH 0:USBC-1, 1:USBC-2 */
  49. uint16_t E_UP_N:1; /*!< bit: 12 ENABLE SUP 1:2 MUX WHEN 0 */
  50. uint16_t S_UP:1; /*!< bit: 13 SELECT UP PATH 0:USBC-1, 1:USBC-2 */
  51. uint16_t HUB_RESET_N:1; /*!< bit: 14 RESET USB HUB WHEN 0, RUN WHEN 1 */
  52. uint16_t HUB_CONNECT:1; /*!< bit: 15 SIGNAL VBUS CONNECT TO USB HUB WHEN 1 */
  53. } bit; /*!< Structure used for bit access */
  54. uint16_t reg; /*!< Type used for register access */
  55. } sr_exp_t;
  56. extern sr_exp_t sr_exp_data;
  57. void SR_EXP_WriteData(void);
  58. void SR_EXP_Init(void);
  59. #endif //_SPI_H_