-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathread_example.c
More file actions
42 lines (33 loc) · 1.04 KB
/
read_example.c
File metadata and controls
42 lines (33 loc) · 1.04 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
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
extern void spi_chip_select(void);
extern void spi_chip_release(void);
extern void spi_write(uint8_t byte);
extern uint8_t spi_read(void);
extern bool read_busy_pin(void);
bool LDL_Chip_read(void *self, const void *opcode, size_t opcode_size, void *data, size_t size)
{
/* unused in this example */
(void)self;
size_t i;
spi_chip_select();
{
/* required for the SX126X series but not the SX127X series
*
* This must occur after selecting the chip since NSS is
* used to wake from sleep, during which busy pin will be set.
*
* consider adding a timeout to recover from a faulty chip */
while(read_busy_pin());
for(i=0U; i < opcode_size; i++){
spi_write(((const uint8_t *)opcode)[i]);
}
for(i=0U; i < size; i++){
((uint8_t *)data)[i] = spi_read();
}
}
spi_chip_release();
/* this would return false if there was a busy timeout */
return true;
}