chen
2024-09-20 292ed46c6066d47289f1330b1c2bcc6d74761f95
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
/*******************************************************************************
 * File Name         : Uart.c
 * Description       :
 * Created on        : 2018Äê4ÔÂ24ÈÕ
 * Author            : www.hido-studio.com
 *******************************************************************************/
 
/*******************************************************************************
 *                              Include Files                                  *
 *******************************************************************************/
#include "stm32f4xx_hal.h"
#include "SPI_hal.h"
 
/*******************************************************************************
 *                                  Macro                                      *
 *******************************************************************************/
 
/*******************************************************************************
 *                             Type Definition                                 *
 *******************************************************************************/
 
/*******************************************************************************
 *                             Local Variable                                  *
 *******************************************************************************/
static SPI_HandleTypeDef *l_apstSPIHandle[SPI_ID_LAST];
 
/*******************************************************************************
 *                        Local Function Declaration                           *
 *******************************************************************************/
 
/*******************************************************************************
 *                             Local Function                                  *
 *******************************************************************************/
/*******************************************************************************
 * Function Name     :
 * Description       :
 * Input             :
 * Output            :
 * Return            :
 * Author            : www.hido-studio.com
 * Modified Date:    : 2018Äê4ÔÂ24ÈÕ
 *******************************************************************************/
HIDO_INT32 SPI_Write(E_SPI_ID _eID, HIDO_UINT8 *_pu8WriteBuf, HIDO_UINT32 _u32Len)
{
    HAL_SPI_Transmit(l_apstSPIHandle[_eID], _pu8WriteBuf, _u32Len, 100 * _u32Len);
 
    return HIDO_OK;
}
 
/*******************************************************************************
 * Function Name     :
 * Description       :
 * Input             :
 * Output            :
 * Return            :
 * Author            : www.hido-studio.com
 * Modified Date:    : 2018Äê4ÔÂ24ÈÕ
 *******************************************************************************/
HIDO_INT32 SPI_ReadWrite(E_SPI_ID _eID, HIDO_UINT8 *_pu8ReadBuf, HIDO_UINT8 *_pu8WriteBuf, HIDO_UINT32 _u32Len)
{
    if(HIDO_NULL == _pu8ReadBuf)
    {
        return SPI_Write(_eID, _pu8WriteBuf, _u32Len);
    }
    else
    {
        HAL_SPI_TransmitReceive(l_apstSPIHandle[_eID], _pu8WriteBuf, _pu8ReadBuf, _u32Len, 100 * _u32Len);
    }
 
    return HIDO_OK;
}
 
/*******************************************************************************
 * Function Name     :
 * Description       :
 * Input             :
 * Output            :
 * Return            :
 * Author            : www.hido-studio.com
 * Modified Date:    : 2018Äê4ÔÂ24ÈÕ
 *******************************************************************************/
HIDO_INT32 SPI_Register(E_SPI_ID _eID, HIDO_VOID *_pSPIHandle)
{
    l_apstSPIHandle[_eID] = (SPI_HandleTypeDef *)_pSPIHandle;
 
    return HIDO_OK;
}