-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhal.cpp
80 lines (65 loc) · 1.96 KB
/
hal.cpp
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
#include <stdint.h> // Find types like "uint8_t"
#include <stdbool.h> // Find type "bool"
#include <SPI.h> // Arduino SPI library
#include <SD.h> // Arduino SD card library
#include "hw_api.h"
#include "Arduino_al.h"
#define SPI_SPEED 200000
void HAL_Delay(uint32_t milliSeconds)
{
delay(milliSeconds);
}
uint8_t HAL_SPI_WriteByte(uint8_t data)
{
SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE0));
digitalWrite(EveChipSelect_PIN, LOW);
SPI.transfer(data);
digitalWrite(EveChipSelect_PIN, HIGH);
SPI.endTransaction();
return 0;
}
// Send a series of bytes (contents of a buffer) through SPI
void HAL_SPI_WriteBuffer(uint8_t *Buffer, uint32_t Length)
{
SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE0));
digitalWrite(EveChipSelect_PIN, LOW);
SPI.transfer(Buffer, Length);
digitalWrite(EveChipSelect_PIN, HIGH);
SPI.endTransaction();
}
// Send a byte through SPI as part of a larger transmission. Does not enable/disable SPI CS
uint8_t HAL_SPI_Write(uint8_t data)
{
// Log("W-0x%02x\n", data);
SPI.transfer(data);
return 0;
}
// Read a series of bytes from SPI and store them in a buffer
void HAL_SPI_ReadBuffer(uint8_t *Buffer, uint32_t Length)
{
uint8_t a = SPI.transfer(0x00); // dummy read
while (Length--)
{
*(Buffer++) = SPI.transfer(0x00);
}
}
// Enable SPI by activating chip select line
void HAL_SPI_Enable(void)
{
SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE0));
digitalWrite(EveChipSelect_PIN, LOW);
}
// Disable SPI by deasserting the chip select line
void HAL_SPI_Disable(void)
{
digitalWrite(EveChipSelect_PIN, HIGH);
SPI.endTransaction();
}
void HAL_Eve_Reset_HW(void)
{
// Reset Eve
SetPin(EvePDN_PIN, 0); // Set the Eve PDN pin low
MyDelay(50); // delay
SetPin(EvePDN_PIN, 1); // Set the Eve PDN pin high
MyDelay(100); // delay
}