-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCS1237_bsp.c
More file actions
113 lines (98 loc) · 2.3 KB
/
CS1237_bsp.c
File metadata and controls
113 lines (98 loc) · 2.3 KB
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
/*
* CS1237_bsp.c
*
* Created on: 2023年4月23日
* Author: Simgor001
*/
#include <CS1237/CS1237.h>
/*==================================================================
* 移植层
* ===============================================================*/
#define _CS1237_SDA_PIN GPIO_Pin_0
#define _CS1237_SDA_GPIO GPIOB
#define _CS1237_CLK_PIN GPIO_Pin_1
#define _CS1237_CLK_GPIO GPIOB
static GPIO_InitTypeDef GPIO_InitStruct;
/**
*@brief 延迟毫秒
*@param ms 毫秒
**/
void _CS1237_ms(uint32_t ms)
{
Delay_Ms(ms);
}
/**
* @brief 延迟一个脉冲
*/
void _CS1237_Delay()
{
//这里至少要延迟500ns
__IO char i = 50;
while(--i);
}
/**
*@brief 初始化GPIO(需要移植)
**/
void _CS1237_GPIO_Init()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Pin = _CS1237_SDA_PIN;
GPIO_Init(_CS1237_SDA_GPIO, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = _CS1237_CLK_PIN;
GPIO_Init(_CS1237_CLK_GPIO, &GPIO_InitStruct);
}
/**
*@brief 设置数据引脚方向为输入(需要移植)
**/
void _CS1237_Input()
{
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;//上拉输入模式
GPIO_InitStruct.GPIO_Pin = _CS1237_SDA_PIN;
GPIO_Init(_CS1237_SDA_GPIO, &GPIO_InitStruct);
}
/**
*@brief 设置数据引脚方向为输出(需要移植)
**/
void _CS1237_Output()
{
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Pin = _CS1237_SDA_PIN;
GPIO_Init(_CS1237_SDA_GPIO, &GPIO_InitStruct);
}
/**
*@brief 时钟输出低电平(需要移植)
**/
void _CS1237_CLK_ResetBits()
{
GPIO_ResetBits(_CS1237_CLK_GPIO, _CS1237_CLK_PIN);
}
/**
*@brief 时钟输出高电平(需要移植)
**/
void _CS1237_CLK_SetBits()
{
GPIO_SetBits(_CS1237_CLK_GPIO, _CS1237_CLK_PIN);
}
/**
*@brief 数据输出低电平(需要移植)
**/
void _CS1237_SDA_ResetBits()
{
GPIO_ResetBits(_CS1237_SDA_GPIO, _CS1237_SDA_PIN);
}
/**
*@brief 数据输出高电平(需要移植)
**/
void _CS1237_SDA_SetBits()
{
GPIO_SetBits(_CS1237_SDA_GPIO, _CS1237_SDA_PIN);
}
/**
*@brief 读取数据线的值(需要移植)
**/
uint8_t _CS1237_SDA_ReadBits()
{
return GPIO_ReadInputDataBit(_CS1237_SDA_GPIO, _CS1237_SDA_PIN);
}