-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform.c
135 lines (115 loc) · 2.25 KB
/
platform.c
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
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <string.h>
#include "platform.h"
/*
* platform_init()
*/
uint8_t
platform_init (usec_ctx *ctx)
{
/* spi init */
spi_init (SPI_PORT, 25*1000*1000);
gpio_set_function (GPIO_MISO, GPIO_FUNC_SPI);
gpio_set_function (GPIO_CS0, GPIO_FUNC_SIO);
gpio_set_function (GPIO_SCLK, GPIO_FUNC_SPI);
gpio_set_function (GPIO_MOSI, GPIO_FUNC_SPI);
/* init gpio direction */
gpio_set_dir (GPIO_RDY, GPIO_IN);
gpio_set_dir (GPIO_RST, GPIO_OUT);
gpio_set_dir (GPIO_CS0, GPIO_OUT);
/* set default gpio values */
gpio_put (GPIO_RST, GPIO_HIGH);
gpio_put (GPIO_CS0, GPIO_HIGH);
/* init platform specific data - not used */
ctx->platform = NULL;
return USEC_DEV_OK;
}
/*
* platform_deinit()
*/
uint8_t
platform_deinit (usec_ctx *ctx)
{
spi_deinit (SPI_PORT);
return USEC_DEV_OK;
}
/*
* platform_delay_ms()
*/
uint8_t
platform_delay_ms (void *platform,
uint16_t delay_ms)
{
sleep_ms (delay_ms);
return USEC_DEV_OK;
}
/*
* platform_hw_reset()
*/
uint8_t
platform_hw_reset (void *platform)
{
gpio_put (GPIO_RST, GPIO_LOW);
platform_delay_ms (platform, 100);
gpio_put (GPIO_RST, GPIO_HIGH);
platform_delay_ms (platform, 200);
return USEC_DEV_OK;
}
/*
* platform_spi_write_byte()
*/
uint8_t
platform_spi_write_byte (void *platform,
uint8_t val)
{
spi_write_blocking (SPI_PORT, &val, 1);
return USEC_DEV_OK;
}
/*
* platform_spi_write_bytes()
*/
uint8_t
platform_spi_write_bytes (void *platform,
uint8_t *data,
uint32_t len)
{
spi_write_blocking (SPI_PORT, data, len);
return USEC_DEV_OK;
}
/*
* platform_spi_read_byte()
*/
uint8_t
platform_spi_read_byte (void *platform)
{
uint8_t val;
spi_read_blocking (SPI_PORT, 0x00, &val, 1);
return val;
}
/*
* platform_spi_cs_high()
*/
uint8_t
platform_spi_cs_high (void *platform,
uint8_t cs_num)
{
gpio_put (GPIO_CS0, GPIO_HIGH);
return USEC_DEV_OK;
}
/*
* platform_spi_cs_low()
*/
uint8_t
platform_spi_cs_low (void *platform,
uint8_t cs_num)
{
gpio_put (GPIO_CS0, GPIO_LOW);
return USEC_DEV_OK;
}
/*
* platform_gpio_read()
*/
uint8_t
platform_gpio_read (void *platform)
{
return gpio_get (GPIO_RDY);
}