rt-thread-official/bsp/ls1cdev/libraries/ls1c_spi.h

101 lines
2.6 KiB
C
Raw Normal View History

2017-10-23 17:10:48 +08:00
/*
* File : ls1c_spi.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-10-23 <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD> first version
*/
// Ӳ<><D3B2>spi<70>ӿڵ<D3BF>ͷ<EFBFBD>ļ<EFBFBD>
#ifndef __OPENLOONGSON_SPI_H
#define __OPENLOONGSON_SPI_H
// SPIģ<49><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
typedef enum
{
LS1C_SPI_0 = 0,
LS1C_SPI_1,
}ls1c_spi_t;
// Ƭѡ
#define LS1C_SPI_INVALID_CS (-1)
#define LS1C_SPI_CS_0 (0)
#define LS1C_SPI_CS_1 (1)
#define LS1C_SPI_CS_2 (2)
#define LS1C_SPI_CS_3 (3)
// ʱ<>Ӽ<EFBFBD><D3BC>Ժ<EFBFBD><D4BA><EFBFBD>λ
#define SPI_CPOL_1 (1)
#define SPI_CPOL_0 (0)
#define SPI_CPHA_1 (1)
#define SPI_CPHA_0 (0)
// Ӳ<><D3B2>SPI<50><49>Ϣ
typedef struct
{
ls1c_spi_t SPIx; // SPIģ<49><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
unsigned long max_speed_hz; // <20><><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD>ٶȣ<D9B6><C8A3><EFBFBD>λhz
unsigned char cs; // Ƭѡ
unsigned char cpol; // ʱ<>Ӽ<EFBFBD><D3BC><EFBFBD>
unsigned char cpha; // ʱ<><CAB1><EFBFBD><EFBFBD>λ
}ls1c_spi_info_t;
/*
* <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>SPIģ<EFBFBD><EFBFBD>
* @spi_info_p SPIģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
*/
void spi_init(ls1c_spi_info_t *spi_info_p);
/*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>ƬѡΪָ<EFBFBD><EFBFBD>״̬
* @spi_info_p SPIģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
* @new_status Ƭѡ<EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD>ȡֵΪ0<EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ƽ
*/
void spi_set_cs(ls1c_spi_info_t *spi_info_p, int new_status);
/*
* ͨ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>SPI<EFBFBD><EFBFBD><EFBFBD>ͽ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
* ע<EFBFBD><EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<EFBFBD>У<EFBFBD><EFBFBD>˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD>ں<EFBFBD>ij<EFBFBD><EFBFBD><EFB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
* @spi_info_p SPIģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
*/
void spi_print_all_regs_info(ls1c_spi_info_t *spi_info_p);
#endif