-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform.c
64 lines (54 loc) · 1.26 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
#include <bcm2835.h>
#include <stdio.h>
#include <unistd.h>
void print(char *str)
{
printf("%s", str);
}
void println(char *str)
{
printf("%s\n", str);
}
void print_buf(uint8_t *buf, uint8_t n)
{
for (uint8_t i = 0; i < n; i++) {
printf("%02X", buf[i]);
}
println("");
}
void delay_ms(int ms)
{
usleep(ms * 1000);
}
void enable_spi()
{
if (!bcm2835_init()) {
println("Unable to init bcm2835.");
return;
}
bcm2835_spi_begin();
bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default
bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); // The default
bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default
bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // the default
}
void disable_spi()
{
bcm2835_spi_end();
bcm2835_close();
}
uint8_t spi_transfer(uint8_t data)
{
return bcm2835_spi_transfer(data);
}
void spi_transfern(uint8_t *buf, uint8_t n)
{
bcm2835_spi_transfern((char *)buf, n);
}
void ce_high()
{
// Put GPIO22/CE/P1-15 high
bcm2835_gpio_fsel(RPI_GPIO_P1_15, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_set(RPI_GPIO_P1_15);
}