-
Notifications
You must be signed in to change notification settings - Fork 14
/
rfm7x_hardware.h
80 lines (57 loc) · 2.18 KB
/
rfm7x_hardware.h
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
/*!
* \brief customize this hardcoded file for your platform
*
* \author Jan Oleksiewicz <jnk0le@hotmail.com>
* \license SPDX-License-Identifier: MIT
*/
#ifndef RFM7X_HARDWARE_H_
#define RFM7X_HARDWARE_H_
//#define USE_EXAMPLE_SPI_MEGA328
//#define USE_EXAMPLE_SPI_XMEGA
//#define USE_EXAMPLE_SPI_STM32F0
#define USE_EXAMPLE_SPI_ARDUINO
//else soft
//arduino only
#ifndef RFM7x_CSN_ARDUINO_PIN
#define RFM7x_CSN_ARDUINO_PIN 10
#endif
#ifndef RFM7x_CE_ARDUINO_PIN
#define RFM7x_CE_ARDUINO_PIN 9
#endif
#define RFM7x_CSN_LOW digitalWrite(RFM7x_CSN_ARDUINO_PIN, LOW)
#define RFM7x_CSN_HI digitalWrite(RFM7x_CSN_ARDUINO_PIN, HIGH)
#define RFM7x_CE_LOW digitalWrite(RFM7x_CE_ARDUINO_PIN, LOW)
#define RFM7x_CE_HI digitalWrite(RFM7x_CE_ARDUINO_PIN, HIGH)
#if !defined(USE_EXAMPLE_SPI_MEGA328)&&!defined(USE_EXAMPLE_SPI_XMEGA)&&!defined(USE_EXAMPLE_SPI_STM32F0)
// tiny 2313 in this case
#define SOFT_SPI_MOSI_DIRSET() DDRB |= (1<<PB5)
#define SOFT_SPI_MISO_DIRSET() DDRB &= ~(1<<PB6)
#define SOFT_SPI_SCK_DIRSET() DDRB |= (1<<PB7)
#define SOFT_SPI_MISO_PULLUP_SET() PORTB |= (1<<PB6)
#define SOFT_SPI_MOSI_HI() PORTB |= (1<<PB5)
#define SOFT_SPI_MOSI_LO() PORTB &= ~(1<<PB5)
#define SOFT_SPI_SCK_HI() PORTB |= (1<<PB7)
#define SOFT_SPI_SCK_LO() PORTB &= ~(1<<PB7)
#define SOFT_SPI_MISO_READ() PINB & (1<<PB6)
#endif
//define here your functions if needed (also add extern declaration above)
#define rfm7x_spi_rw(__data) spi_rw(__data)
#define rfm7x_buff_write(__buff,__len) spi_buff_write(__buff,__len)
#define rfm7x_buff_read(__buff,__len) spi_buff_read(__buff,__len)
#ifdef __cplusplus
extern "C" {
#endif
void rfm7x_io_init(void); // initialize CE and CSN outputs
void spi_init(void);
uint8_t spi_rw(uint8_t data);
//universal spi functions (no CSN/SS handling)
void spi_reg_write(uint8_t reg, uint8_t dat);
uint8_t spi_reg_read(uint8_t reg);
void spi_reg_buff_write(uint8_t reg, uint8_t *buff, uint8_t len);
void spi_buff_write(uint8_t *buff, uint8_t len);
void spi_reg_buff_read(uint8_t reg, uint8_t *buff, uint8_t len);
void spi_buff_read(uint8_t *buff, uint8_t len);
#ifdef __cplusplus
}
#endif
#endif // RFM7X_HARDWARE_H_