50 lines
1.0 KiB
C++
Executable File
50 lines
1.0 KiB
C++
Executable File
#include "driver.h"
|
|
#include <pigpio.h>
|
|
|
|
namespace driver
|
|
{
|
|
namespace {
|
|
Mrf24j *mrf;
|
|
int spi;
|
|
}
|
|
|
|
void callback(int gpio, int level, uint32_t tick) {
|
|
mrf->interrupt_handler();
|
|
mrf->check_flags();
|
|
}
|
|
|
|
void init(Mrf24j *mrf) {
|
|
|
|
gpioInitialise();
|
|
driver::mrf = mrf;
|
|
spi = spiOpen(0, 1000000, 0);
|
|
gpioSetMode(RESET, PI_OUTPUT);
|
|
gpioWrite(RESET, 1);
|
|
gpioSetMode(SPI_CS, PI_OUTPUT);
|
|
cs_high();
|
|
gpioSetAlertFunc(INT, callback);
|
|
}
|
|
|
|
uint8_t transfer(uint8_t data) {
|
|
char txbuff[1], rxbuff[1];
|
|
txbuff[0] = data;
|
|
spiXfer(spi, txbuff, rxbuff, 1);
|
|
return rxbuff[0];
|
|
}
|
|
void reset() {
|
|
gpioWrite(RESET , 0);
|
|
time_sleep(0.01);
|
|
gpioWrite(RESET, 1);
|
|
time_sleep(0.02);
|
|
}
|
|
|
|
void wake() {
|
|
}
|
|
|
|
// INTERRUPT {
|
|
// mrf->interrupt_handler(); // mrf24 object interrupt routine
|
|
// mrf->check_flags();
|
|
// }
|
|
}
|
|
|