spi.h
Go to the documentation of this file.
1 /********************************************************************************************************
2  * @file spi.h
3  *
4  * @brief This is the header file for TLSR8258
5  *
6  * @author Driver Group
7  * @date May 8, 2018
8  *
9  * @par Copyright (c) 2018, Telink Semiconductor (Shanghai) Co., Ltd.
10  * All rights reserved.
11  *
12  * The information contained herein is confidential property of Telink
13  * Semiconductor (Shanghai) Co., Ltd. and is available under the terms
14  * of Commercial License Agreement between Telink Semiconductor (Shanghai)
15  * Co., Ltd. and the licensee or the terms described here-in. This heading
16  * MUST NOT be removed from this file.
17  *
18  * Licensees are granted free, non-transferable use of the information in this
19  * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
20  * @par History:
21  * 1.initial release(DEC. 26 2018)
22  *
23  * @version A001
24  *
25  *******************************************************************************************************/
26 
27 #pragma once
28 #ifndef SPI_H
29 #define SPI_H
30 
31 #include "bsp.h"
32 #include "gpio.h"
33 #include "compiler.h"
41 typedef enum {
45 
46 
50 typedef enum {
51  SPI_MODE0 = 0,
56 
60 typedef enum {
61  SPI_CLK_200K = 0x3c,
62  SPI_CLK_250K = 0x2e,
63  SPI_CLK_500K = 0x17,
64  SPI_CLK_1M = 0x0b,
65  SPI_CLK_2M = 0x05,
66  SPI_CLK_4M = 0x02,
68 
69 
77 static inline void reset_spi_moudle(void)
78 {
80  reg_rst0 &= (~FLD_RST0_SPI);
81 }
100 extern void spi_master_gpio_set(SPI_GPIO_GroupTypeDef PinGrp);
101 
121 extern void spi_slave_gpio_set(SPI_GPIO_GroupTypeDef PinGrp);
122 
131 extern void spi_masterCSpin_select(GPIO_PinTypeDef CSPin);
132 
147 extern void spi_master_init(unsigned char DivClock, SPI_ModeTypeDef Mode);
155 extern void spi_slave_init(unsigned char DivClock, SPI_ModeTypeDef Mode);
169 extern void spi_write(unsigned char *Cmd, int CmdLen, unsigned char *Data, int DataLen, GPIO_PinTypeDef CSPin);
170 
184 extern void spi_read(unsigned char *Cmd, int CmdLen, unsigned char *Data, int DataLen, GPIO_PinTypeDef CSPin);
185 
191 extern void spi_set_share_mode_en(void);
192 
193 #endif
194 
195  //end of GP13
void spi_write(unsigned char *Cmd, int CmdLen, unsigned char *Data, int DataLen, GPIO_PinTypeDef CSPin)
This function serves to write a bulk of data to the SPI slave device specified by the CS pin...
Definition: spi.h:42
void spi_master_init(unsigned char DivClock, SPI_ModeTypeDef Mode)
This function configures the clock and working mode for SPI interface.
void spi_slave_gpio_set(SPI_GPIO_GroupTypeDef PinGrp)
This function selects a pin port for the SPI interface (slave mode)
SPI_ModeTypeDef
Define the mode for SPI interface.
Definition: spi.h:50
Definition: spi.h:51
Definition: spi.h:61
Definition: spi.h:53
void spi_read(unsigned char *Cmd, int CmdLen, unsigned char *Data, int DataLen, GPIO_PinTypeDef CSPin)
This function serves to read a bulk of data from the SPI slave device specified by the CS pin...
Definition: spi.h:65
Definition: spi.h:64
void spi_master_gpio_set(SPI_GPIO_GroupTypeDef PinGrp)
This function selects a pin port for the SPI interface (master mode)
Definition: spi.h:63
Definition: spi.h:43
Definition: spi.h:54
Definition: spi.h:52
SPI_GPIO_GroupTypeDef
Define pin for SPI interface SDO SDI SCK CN A2 A3 A4 D6 B7 B6 D7 D2.
Definition: spi.h:41
GPIO_PinTypeDef
Define GPIO types.
Definition: gpio_8258.h:38
#define reg_rst0
Definition: register_8258.h:143
void spi_slave_init(unsigned char DivClock, SPI_ModeTypeDef Mode)
This function configures the clock and working mode for SPI interface.
static void reset_spi_moudle(void)
This function reset SPI module.
Definition: spi.h:77
SPI_24M_ClkTypeDef
Define the clk for SPI interface(system clock = 24M)
Definition: spi.h:60
Definition: register_8258.h:145
Definition: spi.h:62
Definition: spi.h:66
void spi_masterCSpin_select(GPIO_PinTypeDef CSPin)
This function selects a GPIO pin as CS of SPI function.
void spi_set_share_mode_en(void)
This function use to set the share mode of SPI.