-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsh2_hal_spi.h
122 lines (99 loc) · 3.29 KB
/
sh2_hal_spi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*******************************************************************************
* @file sh2_hal_spi.h
* @brief BNO085 SH2 functions: abstracting STM32 HAL: SPI.
*******************************************************************************
* @note
* Developed using https://github.com/ceva-dsp/sh2-demo-nucleo as reference.
*******************************************************************************
*/
#ifndef NERVE__SH2_HAL_SPI_H
#define NERVE__SH2_HAL_SPI_H
/** Includes. *****************************************************************/
#include "sh2_hal.h"
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_spi.h"
#include "stm32f4xx_hal_tim.h"
/** STM32 port and pin configs. ***********************************************/
extern SPI_HandleTypeDef hspi2;
extern TIM_HandleTypeDef htim5;
// SPI.
#define SH2_HSPI hspi2
#define SH2_HSPI_IRQ SPI2_IRQn // Global SPI interrupt.
#define SH2_CSN_PORT GPIOC
#define SH2_CSN_PIN GPIO_PIN_6
// Timer for signals.
#define SH2_HTIM htim5
// GPIO_EXTI for INTN.
#define SH2_INTN_EXTI_IRQ EXTI0_IRQn
#define SH2_INTN_PORT GPIOC
#define SH2_INTN_PIN GPIO_PIN_0
// GPIO output for wake/1 of 2 communication peripheral selection pins.
#define SH2_PS0_WAKEN_PORT GPIOC
#define SH2_PS0_WAKEN_PIN GPIO_PIN_10
// GPIO output for reset.
#define SH2_RSTN_PORT GPIOC
#define SH2_RSTN_PIN GPIO_PIN_9
/** Definitions. **************************************************************/
// Keep reset asserted this long.
// (Some targets have a long RC decay on reset.)
#define RESET_DELAY_US (10000)
// Timeout time to see first interrupt from SH.
#define START_DELAY_US (2000000)
// How many bytes to read when reading the length field.
#define READ_LEN (4)
// Macros.
#define ARRAY_LEN(a) ((sizeof(a)) / (sizeof(a[0])))
/** Public functions. *********************************************************/
/**
* @brief SH2 SPI HAL open method.
*
* @param self: SH2 HAL instance pointer.
*/
static int sh2_spi_hal_open(sh2_Hal_t *self);
/**
* @brief SH2 SPI HAL close method.
*
* @param self: SH2 HAL instance pointer.
*/
static void sh2_spi_hal_close(sh2_Hal_t *self);
/**
* @brief SH2 SPI HAL read function.
*
* @param self: SH2 HAL instance pointer.
* @param pBuffer: Pointer to the data buffer to store the read data.
* @param len: Number of bytes to read.
* @param t: Timestamp to the time the SH2 interrupt was detected.
*
* @return Status of execution.
* @retval 1 -> Success.
* @retval <= 0 -> Failure/incomplete SHTP transfer.
*/
static int sh2_spi_hal_read(sh2_Hal_t *self, uint8_t *pBuffer, unsigned len,
uint32_t *t);
/**
* @brief SH2 SPI HAL write function.
*
* @param self: SH2 HAL instance pointer.
* @param pBuffer: Pointer to the data buffer whose value is to be written.
* @param len: Number of bytes to write.
*
* @return Status of execution.
* @retval 1 -> Success.
* @retval <= 0 -> Failure/incomplete SHTP transfer.
*/
static int sh2_spi_hal_write(sh2_Hal_t *self, uint8_t *pBuffer, unsigned len);
/**
* @brief SH2 implementation for the current time in us.
*
* @param self: SH2 HAL instance pointer.
*
* @return Status of execution.
*/
static uint32_t sh2_spi_hal_get_time_us(sh2_Hal_t *self);
/**
* @brief STM32 HAL abstraction initialization.
*
* @return Status of execution.
*/
sh2_Hal_t *sh2_hal_init(void);
#endif