]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/protocol/arm_atsam/spi.h
Massdrop keyboard support (#3780)
[qmk_firmware.git] / tmk_core / protocol / arm_atsam / spi.h
1 /*
2 Copyright 2018 Massdrop Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef _SPI_H_
19 #define _SPI_H_
20
21 //TODO: PS: Should bring ports to keyboard configuration
22
23 #define SCSPI           SERCOM2
24
25 #define P14_DIR         0x00004000                             /* PIN14 DIR Bit */
26 #define P14_OUT         0x00004000                             /* PIN14 OUT Bit */
27 #define P15_DIR         0x00008000                             /* PIN15 DIR Bit */
28 #define P15_OUT         0x00008000                             /* PIN15 OUT Bit */
29
30 #define SC2_RCLCK_LO    REG_PORT_OUTCLR1 = P14_OUT             /* PB14 Low, SC2_RCLCK Low                            */
31 #define SC2_RCLCK_HI    REG_PORT_OUTSET1 = P14_OUT             /* PB14 High, SC2_RCLCK High                          */
32 #define SC2_OE_ENA      REG_PORT_OUTCLR1 = P15_OUT             /* PB15 Low, SC2_OE_N Low (Shift register enabled)    */
33 #define SC2_OE_DIS      REG_PORT_OUTSET1 = P15_OUT             /* PB15 High, SC2_OE_N High (Shift register disabled) */
34 #define SC2_DIRSET      REG_PORT_DIRSET1 = P14_DIR | P15_DIR;  /* PB14 PB15 OUT                                      */
35
36 typedef union {
37   struct {
38     uint16_t RSVD4:1;          /*!< bit:      0                                               */
39     uint16_t RSVD3:1;          /*!< bit:      1                                               */
40     uint16_t RSVD2:1;          /*!< bit:      2                                               */
41     uint16_t RSVD1:1;          /*!< bit:      3                                               */
42     uint16_t SDB_N:1;          /*!< bit:      4  SHUTDOWN THE CHIP WHEN 0, RUN WHEN 1         */
43     uint16_t IRST:1;           /*!< bit:      5  RESET THE IS3733 I2C WHEN 1, RUN WHEN 0      */
44     uint16_t SRC_2:1;          /*!< bit:      6  ADVERTISE A SOURCE TO USBC-2 CC              */
45     uint16_t SRC_1:1;          /*!< bit:      7  ADVERTISE A SOURCE TO USBC-1 CC              */
46     uint16_t E_VBUS_2:1;       /*!< bit:      8  ENABLE 5V OUT TO USBC-2 WHEN 1               */
47     uint16_t E_VBUS_1:1;       /*!< bit:      9  ENABLE 5V OUT TO USBC-1 WHEN 1               */
48     uint16_t E_DN1_N:1;        /*!< bit:     10  ENABLE DN1 1:2 MUX WHEN 0                    */
49     uint16_t S_DN1:1;          /*!< bit:     11  SELECT DN1 PATH 0:USBC-1, 1:USBC-2           */
50     uint16_t E_UP_N:1;         /*!< bit:     12  ENABLE SUP 1:2 MUX WHEN 0                    */
51     uint16_t S_UP:1;           /*!< bit:     13  SELECT UP PATH 0:USBC-1, 1:USBC-2            */
52     uint16_t HUB_RESET_N:1;    /*!< bit:     14  RESET USB HUB WHEN 0, RUN WHEN 1             */
53     uint16_t HUB_CONNECT:1;    /*!< bit:     15  SIGNAL VBUS CONNECT TO USB HUB WHEN 1        */
54   } bit;                       /*!< Structure used for bit access                             */
55   uint16_t reg;                /*!< Type      used for register access                        */
56 } Srdata_t;
57
58 extern Srdata_t srdata;
59
60 void SPI_WriteSRData(void);
61 void SPI_Init(void);
62
63 #endif //_SPI_H_