|
@@ -0,0 +1,140 @@
|
|
1
|
+#include "stm32f4xx_hal.h"
|
|
2
|
+
|
|
3
|
+#ifndef _GINPUT_LLD_MOUSE_BOARD_H
|
|
4
|
+#define _GINPUT_LLD_MOUSE_BOARD_H
|
|
5
|
+
|
|
6
|
+// Resolution and Accuracy Settings
|
|
7
|
+#define GMOUSE_ADS7843_PEN_CALIBRATE_ERROR 8
|
|
8
|
+#define GMOUSE_ADS7843_PEN_CLICK_ERROR 6
|
|
9
|
+#define GMOUSE_ADS7843_PEN_MOVE_ERROR 4
|
|
10
|
+#define GMOUSE_ADS7843_FINGER_CALIBRATE_ERROR 14
|
|
11
|
+#define GMOUSE_ADS7843_FINGER_CLICK_ERROR 18
|
|
12
|
+#define GMOUSE_ADS7843_FINGER_MOVE_ERROR 14
|
|
13
|
+
|
|
14
|
+// How much extra data to allocate at the end of the GMouse structure for the board's use
|
|
15
|
+#define GMOUSE_ADS7843_BOARD_DATA_SIZE 0
|
|
16
|
+
|
|
17
|
+static SPI_HandleTypeDef _hspi;
|
|
18
|
+
|
|
19
|
+static bool_t init_board(GMouse* m, unsigned driverinstance)
|
|
20
|
+{
|
|
21
|
+ GPIO_InitTypeDef GPIO_InitStruct;
|
|
22
|
+
|
|
23
|
+ (void)m;
|
|
24
|
+ (void)driverinstance;
|
|
25
|
+
|
|
26
|
+ // Peripheral clocks
|
|
27
|
+ __HAL_RCC_GPIOA_CLK_ENABLE();
|
|
28
|
+ __HAL_RCC_GPIOB_CLK_ENABLE();
|
|
29
|
+ __HAL_RCC_GPIOC_CLK_ENABLE();
|
|
30
|
+ __HAL_RCC_SPI1_CLK_ENABLE();
|
|
31
|
+
|
|
32
|
+ // GPIO pins
|
|
33
|
+ {
|
|
34
|
+ // PA4 (chip select)
|
|
35
|
+ GPIO_InitStruct.Pin = GPIO_PIN_4;
|
|
36
|
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
37
|
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
38
|
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
|
39
|
+ GPIO_InitStruct.Alternate = 0;
|
|
40
|
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
41
|
+
|
|
42
|
+ // PA5 (SPI SCK)
|
|
43
|
+ GPIO_InitStruct.Pin = GPIO_PIN_5;
|
|
44
|
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
45
|
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
46
|
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
|
47
|
+ GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
|
|
48
|
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
49
|
+
|
|
50
|
+ // PA6 (SPI MISO)
|
|
51
|
+ GPIO_InitStruct.Pin = GPIO_PIN_6;
|
|
52
|
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
53
|
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
54
|
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
|
55
|
+ GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
|
|
56
|
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
57
|
+
|
|
58
|
+ // PA7 (SPI MOSI)
|
|
59
|
+ GPIO_InitStruct.Pin = GPIO_PIN_7;
|
|
60
|
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
61
|
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
62
|
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
|
63
|
+ GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
|
|
64
|
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
65
|
+
|
|
66
|
+ // PB1 (busy)
|
|
67
|
+ GPIO_InitStruct.Pin = GPIO_PIN_1;
|
|
68
|
+ GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
69
|
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
70
|
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
|
71
|
+ GPIO_InitStruct.Alternate = 0;
|
|
72
|
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
73
|
+
|
|
74
|
+ // PC4 (pen IRQ)
|
|
75
|
+ GPIO_InitStruct.Pin = GPIO_PIN_4;
|
|
76
|
+ GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
77
|
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
78
|
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
|
79
|
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ // SPI
|
|
83
|
+ _hspi.Instance = SPI1;
|
|
84
|
+ _hspi.Init.Mode = SPI_MODE_MASTER;
|
|
85
|
+ _hspi.Init.Direction = SPI_DIRECTION_2LINES;
|
|
86
|
+ _hspi.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
87
|
+ _hspi.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
88
|
+ _hspi.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
89
|
+ _hspi.Init.NSS = SPI_NSS_SOFT;
|
|
90
|
+ _hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
|
|
91
|
+ _hspi.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
92
|
+ _hspi.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
93
|
+ _hspi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
94
|
+ _hspi.Init.CRCPolynomial = 10;
|
|
95
|
+ if (HAL_SPI_Init(&_hspi) != HAL_OK) {
|
|
96
|
+ return FALSE;
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ return TRUE;
|
|
100
|
+}
|
|
101
|
+
|
|
102
|
+static GFXINLINE bool_t getpin_pressed(GMouse* m)
|
|
103
|
+{
|
|
104
|
+ (void)m;
|
|
105
|
+
|
|
106
|
+ if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_4) == GPIO_PIN_RESET)
|
|
107
|
+ return TRUE;
|
|
108
|
+
|
|
109
|
+ return FALSE;
|
|
110
|
+}
|
|
111
|
+
|
|
112
|
+static GFXINLINE void aquire_bus(GMouse* m)
|
|
113
|
+{
|
|
114
|
+ (void)m;
|
|
115
|
+
|
|
116
|
+ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
|
|
117
|
+}
|
|
118
|
+
|
|
119
|
+static GFXINLINE void release_bus(GMouse* m)
|
|
120
|
+{
|
|
121
|
+ (void)m;
|
|
122
|
+
|
|
123
|
+ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
|
|
124
|
+}
|
|
125
|
+
|
|
126
|
+static GFXINLINE uint16_t read_value(GMouse* m, uint16_t reg)
|
|
127
|
+{
|
|
128
|
+ uint8_t txbuf[3] = {0, 0, 0};
|
|
129
|
+ uint8_t rxbuf[3] = {0, 0, 0};
|
|
130
|
+ uint16_t ret;
|
|
131
|
+
|
|
132
|
+ (void)m;
|
|
133
|
+
|
|
134
|
+ txbuf[0] = reg;
|
|
135
|
+ HAL_SPI_TransmitReceive(&_hspi, txbuf, rxbuf, 3, 1000);
|
|
136
|
+
|
|
137
|
+ return (rxbuf[1] << 5) | (rxbuf[2] >> 3);
|
|
138
|
+}
|
|
139
|
+
|
|
140
|
+#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
|