|
|
@@ -1,6 +1,7 @@
|
|
1
|
1
|
#include <avr/io.h>
|
|
2
|
2
|
#include <util/delay.h>
|
|
3
|
3
|
|
|
|
4
|
+#include "spi.h"
|
|
4
|
5
|
#include "bme280.h"
|
|
5
|
6
|
#include "bme280_interface.h"
|
|
6
|
7
|
|
|
|
@@ -98,20 +99,14 @@ int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16
|
|
98
|
99
|
/* unused parameters */
|
|
99
|
100
|
(void)dev_id;
|
|
100
|
101
|
|
|
101
|
|
- /* SPI routine */
|
|
102
|
|
-
|
|
103
|
|
- /* TODO pack into spi byte transfer function */
|
|
104
|
|
- BME_CSN_PORT &= ~(1<<BME_CSN_PIN); // Start the transmission
|
|
105
|
|
- SPDR = reg_addr;
|
|
106
|
|
- while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
|
|
|
102
|
+ SPI_Start_Transmission(&BME_CSN_PORT, BME_CSN_PIN);
|
|
|
103
|
+ SPI_Transfer_Byte(reg_addr);
|
|
107
|
104
|
|
|
108
|
105
|
for (uint16_t i = 0; i < len; i ++)
|
|
109
|
106
|
{
|
|
110
|
|
- SPDR = 0x0; /* value doesn't matter */
|
|
111
|
|
- while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
|
|
112
|
|
- reg_data[i] = SPDR;
|
|
|
107
|
+ reg_data[i] = SPI_Transfer_Byte(0x0); /* Value to send doesn't matter */
|
|
113
|
108
|
}
|
|
114
|
|
- BME_CSN_PORT |= (1<<BME_CSN_PIN); // Stop the transmission
|
|
|
109
|
+ SPI_Stop_Transmission(&BME_CSN_PORT, BME_CSN_PIN);
|
|
115
|
110
|
|
|
116
|
111
|
return rslt;
|
|
117
|
112
|
}
|
|
|
@@ -124,16 +119,14 @@ int8_t user_spi_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint1
|
|
124
|
119
|
(void)dev_id;
|
|
125
|
120
|
|
|
126
|
121
|
/* SPI routine */
|
|
127
|
|
- BME_CSN_PORT &= ~(1<<BME_CSN_PIN); // Start the transmission
|
|
128
|
|
- SPDR = reg_addr;
|
|
129
|
|
- while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
|
|
|
122
|
+ SPI_Start_Transmission(&BME_CSN_PORT, BME_CSN_PIN);
|
|
|
123
|
+ SPI_Transfer_Byte(reg_addr);
|
|
130
|
124
|
|
|
131
|
125
|
for (uint16_t i = 0; i < len; i ++)
|
|
132
|
126
|
{
|
|
133
|
|
- SPDR = reg_data[i]; /* value doesn't matter */
|
|
134
|
|
- while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
|
|
|
127
|
+ SPI_Transfer_Byte(reg_data[i]);
|
|
135
|
128
|
}
|
|
136
|
|
- BME_CSN_PORT |= (1<<BME_CSN_PIN); // Stop the transmission
|
|
|
129
|
+ SPI_Stop_Transmission(&BME_CSN_PORT, BME_CSN_PIN);
|
|
137
|
130
|
|
|
138
|
131
|
return rslt;
|
|
139
|
132
|
}
|